From patchwork Wed Mar 3 17:04:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11481 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 A41D1BD1F1 for ; Wed, 3 Mar 2021 17:04:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7FEA668AA3; Wed, 3 Mar 2021 18:04:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="S3UVdB3+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F25B468A91 for ; Wed, 3 Mar 2021 18:04:29 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 80E088F3; Wed, 3 Mar 2021 18:04:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614791069; bh=Jv8Pe8Zus82M8zdmYNO6I6UwL+kYDk7H8hZAB+AsqBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S3UVdB3+3MSeh2Q5ou3mSu6qcYukk60RrIk5zkg2hfL1Nuh4BcvyfW5P290wlFwx7 WOHp1cZtLT0T2pBD1fIOt3T8F6f7+rk/r1rdzmfnMRUaMhdCK+9JMwjsPJG/zRteXH bFq7tYMao7IOSFDbUCMSP49WWDZXVKaUTmEGEJhk= From: Kieran Bingham To: libcamera devel Date: Wed, 3 Mar 2021 17:04:24 +0000 Message-Id: <20210303170426.189648-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303170426.189648-1-kieran.bingham@ideasonboard.com> References: <20210303170426.189648-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: pipeline: ipu3: Fix spelling error 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" Fix trivial spelling mistake. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/frames.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index 37932dc779a5..151ebfe7ca5f 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -52,7 +52,7 @@ IPU3Frames::Info *IPU3Frames::create(Request *request) FrameBuffer *paramBuffer = availableParamBuffers_.front(); if (availableStatBuffers_.empty()) { - LOG(IPU3, Error) << "Statisitc buffer underrun"; + LOG(IPU3, Error) << "Statistics buffer underrun"; return nullptr; } FrameBuffer *statBuffer = availableStatBuffers_.front(); From patchwork Wed Mar 3 17:04:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11482 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 4022CBD1F1 for ; Wed, 3 Mar 2021 17:04:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C626868AA7; Wed, 3 Mar 2021 18:04:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HIpaSri8"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 450DA68A91 for ; Wed, 3 Mar 2021 18:04:30 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D67D68DE; Wed, 3 Mar 2021 18:04:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614791070; bh=uO27BIlzWeSyMUE85FWKqTxyU+/kPwFYPDJQo+Bl5Vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HIpaSri8Bv9VyzNbC77Q37SymmR5yhetS1Z+t9aR4hg7I/EkQVf/nFyX8C/yDDUFY beZcr2BIW5nETyrI1jkZe9ooOpbNFC4QekLI78rOjhgtCNjAkehtQ8U2QYUCEcVenP nfwFe0URc0D6W7Q29WhztgkSPEmW4twJSRj7WeXQ= From: Kieran Bingham To: libcamera devel Date: Wed, 3 Mar 2021 17:04:25 +0000 Message-Id: <20210303170426.189648-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303170426.189648-1-kieran.bingham@ideasonboard.com> References: <20210303170426.189648-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: pipeline: ipu3: Ensure that IPU3Frames::info is not used after delete 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" When the IPU3Frames completes, it deletes the internal info storage. This storage contains the pointer to the Request, but in some cases the pointer was being accessed after the info structure was removed. Ensure that the Request is obtained before attempting to complete to obtain a valid pointer. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- This may be a further sign that we should rework how this is allocated, but for now - this patch fixes the crash which can occur when shutting down streams. The blank line addition in the first hunk is intentional. src/libcamera/pipeline/ipu3/ipu3.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 2b4d31500533..9539393e5d84 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1164,6 +1164,7 @@ void IPU3CameraData::queueFrameAction(unsigned int id, * in action.controls to register additional metadata. */ Request *request = info->request; + info->metadataProcessed = true; if (frameInfos_.tryComplete(info)) pipe_->completeRequest(request); @@ -1253,8 +1254,15 @@ void IPU3CameraData::paramBufferReady(FrameBuffer *buffer) return; info->paramDequeued = true; + + /* + * tryComplete() will delete info if it completes the IPU3Frame. + * In that event, we must have obtained the Request before hand. + */ + Request *request = info->request; + if (frameInfos_.tryComplete(info)) - pipe_->completeRequest(info->request); + pipe_->completeRequest(request); } void IPU3CameraData::statBufferReady(FrameBuffer *buffer) @@ -1265,8 +1273,16 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) if (buffer->metadata().status == FrameMetadata::FrameCancelled) { info->metadataProcessed = true; + + /* + * tryComplete() will delete info if it completes the IPU3Frame. + * In that event, we must have obtained the Request before hand. + */ + Request *request = info->request; + if (frameInfos_.tryComplete(info)) - pipe_->completeRequest(info->request); + pipe_->completeRequest(request); + return; } From patchwork Wed Mar 3 17:04:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11483 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 8375CBD80E for ; Wed, 3 Mar 2021 17:04:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3FBB368AA9; Wed, 3 Mar 2021 18:04:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gMG3ZeQj"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9136868A91 for ; Wed, 3 Mar 2021 18:04:30 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F24A8CA; Wed, 3 Mar 2021 18:04:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614791070; bh=hKEekJNtVNA4pumGwYYfJyLAUPQc0ElpV43hQ60SklQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gMG3ZeQj38SGnzyXnJIBpouoZGC+GbOvAxDJanmUO04aGU12pQoZ7VEnNyPxS1rh7 ZDXuVv+nnFZt5fjJV9GcNrNbf2577X8gubvu+A+NlngU7hTS8NVUFK8xtDPLuEh+nn WbDEX/00+MrVUgLVvMySfrjFAzsX9UpHUZl/bW38= From: Kieran Bingham To: libcamera devel Date: Wed, 3 Mar 2021 17:04:26 +0000 Message-Id: <20210303170426.189648-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303170426.189648-1-kieran.bingham@ideasonboard.com> References: <20210303170426.189648-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: v4l2_videodevice: Prevent queueing buffers without a cache 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" The v4l2 buffer cache allows us to map incoming buffers to an instance of the V4L2 Buffer required to actually queue. If the cache_ is not available, then the buffers required to allow queuing to a device have been released, and this indicates an issue at the pipeline handler. This could be a common mistake, as it could happen if a pipeline handler always requeues buffers to the device after they complete, without checking if they are cancelled. That can then lead to trying to queue a buffer to a device which no longer expects buffers, so add a loud message to indicate what has happened but return an error without fatally crashing. Signed-off-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_videodevice.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index c77e1aff7978..6129ce529afc 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1390,6 +1390,16 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) struct v4l2_buffer buf = {}; int ret; + /* + * Pipeline handlers should not requeue buffers after releasing the + * buffers on the device. Any occurence of this error should be fixed + * in the pipeline handler directly. + */ + if (!cache_) { + LOG(V4L2, Error) << "No BufferCache available to queue."; + return -ENOENT; + } + ret = cache_->get(*buffer); if (ret < 0) return ret;