From patchwork Tue Sep 28 15:36:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 13968 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8EAA6C3243 for ; Tue, 28 Sep 2021 15:36:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1021369191; Tue, 28 Sep 2021 17:36:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DLghld18"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1D1AF69188 for ; Tue, 28 Sep 2021 17:36:38 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id z2so3852826wmc.3 for ; Tue, 28 Sep 2021 08:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hpiMk/MuT64ENdNHPVsEEKguezLcZeGm2nzBpX1K8kM=; b=DLghld18eC4W7yY/Mu4wwFINEn0YjeotgtDd4ObIkoP81l72H+XK4IzwXVCC8Rj6Hv qsOYKCEEKWH4RhAP1NtAdWvMeL7JBnHU3PWFHdWWK6eFV82DaAsrHxCVnQ8yXhUmv+Nf bpuxx2CgMXs2QtIKNxJjiOF5nxofWL32GY+DWxCiOL1tUBlLEEbekc7IJ16hhPdg9IIm YwBq6w1NFnwyltk4/Vk5i+WYXPBiF/wa+D4q45dhMJt6Aa+vOJP5qTZW7hMwYRcr4Jvn vkNS5rD1XP7gO3b5+Zg3e9Y3HXVHimC0Dd6NfIO9GeSNMRNBZ8C7Khe9mVjUSlITz8s+ 2AOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hpiMk/MuT64ENdNHPVsEEKguezLcZeGm2nzBpX1K8kM=; b=Pahwn/lbCaGHpaH5OnlQ58uTbveqeeUmNSZNdj3NhkiHdChgZjojFZU9zqYCO6/VRk +KYTJ42hOV1ktHz4nxcF+WDI3tIsnEuh+YaF4TpvpvaztFpeeA/OC+v70Olr1ju1kTeH RGeAuu2zayY5ksUtTLbI6noxMLLPzJoOItMf7uQBuKrOb1KgbQpzBDRStFBVpAW0LnDF 1KL3eKgxgmz+e061gZG7YCixYwlKpGIr5H6dqwYKFfovtNnM2305m+MkG+kapQU5PKi8 8Ko95j/h6QKkh1gcWWWLeGExnRq4SVHkQbHz4xFuXvFJQ0HEaIf0G2iOcZrTQc1dyUne lgjg== X-Gm-Message-State: AOAM531x4gL9unriKUBNdY9dqXXv1OBfMtzdiK5Ns5HYANM57LrtSae/ Gqd2SYLY5Zy0gsBtbmDAhQTvokOt2r/RcP/f X-Google-Smtp-Source: ABdhPJxXONvc3AoeI9fSmITTYoORF7bVQO6oUm8kfcww4TwcF8FpnENawY/Btve5UGFTIGo5Q+ITcA== X-Received: by 2002:a7b:c409:: with SMTP id k9mr5341122wmi.153.1632843397292; Tue, 28 Sep 2021 08:36:37 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id d1sm22562735wrr.72.2021.09.28.08.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 08:36:36 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Sep 2021 16:36:34 +0100 Message-Id: <20210928153634.5864-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: Fix crash caused by reading uninitialised delayed controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This fixes bug https://bugs.libcamera.org/show_bug.cgi?id=74. The cause is that we read out delayed values using a frame's sequence number (DelayedControls::get). But we fill the values up (DelayedControls::applyControls) incrementing writeCount by only one even if the sequence number has jumped by several since last time. This is exactly what happens when frames are being dropped. So the fix is to increment writeCount by "as much as the sequence number has jumped since last time", which means that we just follow the sequence number directly. Signed-off-by: David Plowman Reviewed-by: Laurent Pinchart Reviewed-by: Naushir Patuck Tested-by: Naushir Patuck Tested-by: Jacopo Mondi Reviewed-by: Jacopo Mondi --- src/libcamera/delayed_controls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp index 90ce7e0b..9667187e 100644 --- a/src/libcamera/delayed_controls.cpp +++ b/src/libcamera/delayed_controls.cpp @@ -279,7 +279,7 @@ void DelayedControls::applyControls(uint32_t sequence) } } - writeCount_++; + writeCount_ = sequence - firstSequence_ + 1; while (writeCount_ > queueCount_) { LOG(DelayedControls, Debug)