{"id":24038,"url":"https://patchwork.libcamera.org/api/1.1/patches/24038/?format=json","web_url":"https://patchwork.libcamera.org/patch/24038/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250730102733.21314-3-laurent.pinchart@ideasonboard.com>","date":"2025-07-30T10:27:33","name":"[v3,2/2] libcamera: v4l2_videodevice: Use scope_exit","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"96ae4484f0dfd04dbb945879a76057bb20e04808","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24038/mbox/","series":[{"id":5350,"url":"https://patchwork.libcamera.org/api/1.1/series/5350/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5350","date":"2025-07-30T10:27:31","name":"libcamera: Introduce and use scope_exit","version":3,"mbox":"https://patchwork.libcamera.org/series/5350/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24038/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24038/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id AFFBBBDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 30 Jul 2025 10:27:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 50F57691FE;\n\tWed, 30 Jul 2025 12:27:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A873C6914D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 30 Jul 2025 12:27:45 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 42C5DC67\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 30 Jul 2025 12:27:02 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"JXTGLJVg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753871222;\n\tbh=HQQpoa160C8j3jA6/OnpsPJXD9zOnZ0N0TshqI/S0o4=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=JXTGLJVgKrR26DsMI1OfjSgxkkPoOAutNJxxbkuU+PuHNxzgiFCZVYK+LFDsFd8d8\n\tRrJdkHU8pYDAAgejKyq7olHKs+eubfRro4CJk47wd8oM5fGyeBbL02c+bwGvkiw4Wd\n\t7MKBxRh/9Gq+1CNWsawzKr1Do+6ziMapa2V5aksg=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v3 2/2] libcamera: v4l2_videodevice: Use scope_exit","Date":"Wed, 30 Jul 2025 13:27:33 +0300","Message-ID":"<20250730102733.21314-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.49.1","In-Reply-To":"<20250730102733.21314-1-laurent.pinchart@ideasonboard.com>","References":"<20250730102733.21314-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The V4L2VideoDevice::queueBuffer() function performs the same cleanup\naction in many error paths. Use scope_exit to simplify it.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/v4l2_videodevice.cpp | 11 +++--------\n 1 file changed, 3 insertions(+), 8 deletions(-)","diff":"diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 71cc7e895d8c..d206244fa9a6 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1668,6 +1668,8 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n \tif (ret < 0)\n \t\treturn ret;\n \n+\tauto guard = utils::scope_exit{ [&]() { cache_->put(buf.index); } };\n+\n \tbuf.index = ret;\n \tbuf.type = bufferType_;\n \tbuf.memory = memoryType_;\n@@ -1683,15 +1685,11 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n \t */\n \tif (planes.size() < numV4l2Planes) {\n \t\tLOG(V4L2, Error) << \"Frame buffer has too few planes\";\n-\t\tcache_->put(buf.index);\n-\n \t\treturn -EINVAL;\n \t}\n \n \tif (planes.size() != numV4l2Planes && !buffer->_d()->isContiguous()) {\n \t\tLOG(V4L2, Error) << \"Device format requires contiguous buffer\";\n-\t\tcache_->put(buf.index);\n-\n \t\treturn -EINVAL;\n \t}\n \n@@ -1734,8 +1732,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n \t\t\t\tif (i != planes.size() - 1 && bytesused != length) {\n \t\t\t\t\tLOG(V4L2, Error)\n \t\t\t\t\t\t<< \"Holes in multi-planar buffer not supported\";\n-\t\t\t\t\tcache_->put(buf.index);\n-\n \t\t\t\t\treturn -EINVAL;\n \t\t\t\t}\n \t\t\t}\n@@ -1785,8 +1781,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to queue buffer \" << buf.index << \": \"\n \t\t\t<< strerror(-ret);\n-\t\tcache_->put(buf.index);\n-\n \t\treturn ret;\n \t}\n \n@@ -1798,6 +1792,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n \n \tqueuedBuffers_[buf.index] = buffer;\n \n+\tguard.release();\n \treturn 0;\n }\n \n","prefixes":["v3","2/2"]}