[{"id":35284,"web_url":"https://patchwork.libcamera.org/comment/35284/","msgid":"<175446218172.7787.16694264400455586605@localhost>","date":"2025-08-06T06:36:21","subject":"Re: [PATCH v4 2/2] libcamera: v4l2_videodevice: Use scope_exit","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Laurent,\n\nThank you for the patch. \n\nQuoting Laurent Pinchart (2025-08-05 01:31:51)\n> The V4L2VideoDevice::queueBuffer() function performs the same cleanup\n> action in many error paths. Use scope_exit to simplify it.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> \n\nCheers,\nStefan\n\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 11 +++--------\n>  1 file changed, 3 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 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>         if (ret < 0)\n>                 return ret;\n>  \n> +       auto guard = utils::scope_exit{ [&]() { cache_->put(buf.index); } };\n> +\n>         buf.index = ret;\n>         buf.type = bufferType_;\n>         buf.memory = memoryType_;\n> @@ -1683,15 +1685,11 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>          */\n>         if (planes.size() < numV4l2Planes) {\n>                 LOG(V4L2, Error) << \"Frame buffer has too few planes\";\n> -               cache_->put(buf.index);\n> -\n>                 return -EINVAL;\n>         }\n>  \n>         if (planes.size() != numV4l2Planes && !buffer->_d()->isContiguous()) {\n>                 LOG(V4L2, Error) << \"Device format requires contiguous buffer\";\n> -               cache_->put(buf.index);\n> -\n>                 return -EINVAL;\n>         }\n>  \n> @@ -1734,8 +1732,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>                                 if (i != planes.size() - 1 && bytesused != length) {\n>                                         LOG(V4L2, Error)\n>                                                 << \"Holes in multi-planar buffer not supported\";\n> -                                       cache_->put(buf.index);\n> -\n>                                         return -EINVAL;\n>                                 }\n>                         }\n> @@ -1785,8 +1781,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>                 LOG(V4L2, Error)\n>                         << \"Failed to queue buffer \" << buf.index << \": \"\n>                         << strerror(-ret);\n> -               cache_->put(buf.index);\n> -\n>                 return ret;\n>         }\n>  \n> @@ -1798,6 +1792,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>  \n>         queuedBuffers_[buf.index] = buffer;\n>  \n> +       guard.release();\n>         return 0;\n>  }\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","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 3CE17BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 Aug 2025 06:36:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 040C56921A;\n\tWed,  6 Aug 2025 08:36:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 64BEA61464\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 Aug 2025 08:36:24 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:cc39:a2ec:4c28:e184])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 22B0F17EB; \n\tWed,  6 Aug 2025 08:35:36 +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=\"DUkaqme7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754462136;\n\tbh=VqCuyFoN5kdT0BSPL9Lvh1SuM70brICemkKCyzbmP/Q=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=DUkaqme7O/Dkln9ox3d9Arnl5FhkwopQ9B9SFlBhXSg/FL7zTefxHlIxcZG6gvu9P\n\tEqRhSf7LoxrsdQwc7WGjApkBkd0V025Lly8F1l0yXiea2CBzBqt6tIbYggnxJhP7t4\n\twCf7DbqM8vRTxYrGm6BELM9Fkf0ws80uca6OECNo=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250804233152.11538-3-laurent.pinchart@ideasonboard.com>","References":"<20250804233152.11538-1-laurent.pinchart@ideasonboard.com>\n\t<20250804233152.11538-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v4 2/2] libcamera: v4l2_videodevice: Use scope_exit","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 06 Aug 2025 08:36:21 +0200","Message-ID":"<175446218172.7787.16694264400455586605@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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>"}},{"id":35285,"web_url":"https://patchwork.libcamera.org/comment/35285/","msgid":"<175447209933.1641235.13214650462161849330@ping.linuxembedded.co.uk>","date":"2025-08-06T09:21:39","subject":"Re: [PATCH v4 2/2] libcamera: v4l2_videodevice: Use scope_exit","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2025-08-05 00:31:51)\n> The V4L2VideoDevice::queueBuffer() function performs the same cleanup\n> action in many error paths. Use scope_exit to simplify it.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nIndeed, this looks cleaner to me.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 11 +++--------\n>  1 file changed, 3 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 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>         if (ret < 0)\n>                 return ret;\n>  \n> +       auto guard = utils::scope_exit{ [&]() { cache_->put(buf.index); } };\n> +\n>         buf.index = ret;\n>         buf.type = bufferType_;\n>         buf.memory = memoryType_;\n> @@ -1683,15 +1685,11 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>          */\n>         if (planes.size() < numV4l2Planes) {\n>                 LOG(V4L2, Error) << \"Frame buffer has too few planes\";\n> -               cache_->put(buf.index);\n> -\n>                 return -EINVAL;\n>         }\n>  \n>         if (planes.size() != numV4l2Planes && !buffer->_d()->isContiguous()) {\n>                 LOG(V4L2, Error) << \"Device format requires contiguous buffer\";\n> -               cache_->put(buf.index);\n> -\n>                 return -EINVAL;\n>         }\n>  \n> @@ -1734,8 +1732,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>                                 if (i != planes.size() - 1 && bytesused != length) {\n>                                         LOG(V4L2, Error)\n>                                                 << \"Holes in multi-planar buffer not supported\";\n> -                                       cache_->put(buf.index);\n> -\n>                                         return -EINVAL;\n>                                 }\n>                         }\n> @@ -1785,8 +1781,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>                 LOG(V4L2, Error)\n>                         << \"Failed to queue buffer \" << buf.index << \": \"\n>                         << strerror(-ret);\n> -               cache_->put(buf.index);\n> -\n>                 return ret;\n>         }\n>  \n> @@ -1798,6 +1792,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n>  \n>         queuedBuffers_[buf.index] = buffer;\n>  \n> +       guard.release();\n>         return 0;\n>  }\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","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 C29FEBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 Aug 2025 09:21:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 029F1691F5;\n\tWed,  6 Aug 2025 11:21:44 +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 3701E6084D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 Aug 2025 11:21:42 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B42ADEBA;\n\tWed,  6 Aug 2025 11:20:53 +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=\"DJNKFJyy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754472053;\n\tbh=MHHvVSB5IvndTmkRVx5IE4muiyhbJP6jw0ahXpH27YU=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=DJNKFJyyZwMjesT6UxmGvVtj9QJEbh1JMQRWZmMPJT3vELSPIHhs2++cTJFsUqygK\n\tk9OFoqEY5oe5926alLzhfIR1J62KVYSWB6l/Vtx1GK9KVTxOEQsk8kwI/3DFm2nNzl\n\t3EqCAmNZFJ4gE4mUsFIeqnep+zHUjioexPLDPsfI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250804233152.11538-3-laurent.pinchart@ideasonboard.com>","References":"<20250804233152.11538-1-laurent.pinchart@ideasonboard.com>\n\t<20250804233152.11538-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v4 2/2] libcamera: v4l2_videodevice: Use scope_exit","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 06 Aug 2025 10:21:39 +0100","Message-ID":"<175447209933.1641235.13214650462161849330@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]