[{"id":34995,"web_url":"https://patchwork.libcamera.org/comment/34995/","msgid":"<175312522037.50296.15209729881476131638@ping.linuxembedded.co.uk>","date":"2025-07-21T19:13:40","subject":"Re: [PATCH 1/1] libcamera: Put buffer back to V4L2BufferCache when\n\tVIDIOC_QBUF fails","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Harvey Yang (2024-09-12 06:09:39)\n> From: Han-Lin Chen <hanlinchen@chromium.org>\n> \n> The patch puts buffer back to V4L2BufferCache when VIDIOC_QBUF fails\n> in V4L2VideoDevice. This is to avoid cache leaks and causing assert.\n> \n\nThis seems reasonable - although could probably now be implemented in\nless code with the new ScopeExitActions class which wasn't around when\nthis was posted I expect...\n\nHowever - while we could do a version with ScopeExitActions - I think\nthis is still correct *AND* fixes the error paths in\nV4L2VideoDevice::queueBuffer() which are clearly leaking buffer cache\nentries.\n\nSo:\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n\n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n> Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 8 ++++++++\n>  1 file changed, 8 insertions(+)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 76742e18..75a2cdb1 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1626,11 +1626,15 @@ 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> @@ -1673,6 +1677,8 @@ 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> @@ -1722,6 +1728,8 @@ 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> -- \n> 2.46.0.598.g6f2099f65c-goog\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 2F9CFBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Jul 2025 19:13:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7E50869012;\n\tMon, 21 Jul 2025 21:13:45 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E4AB6900C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jul 2025 21:13:43 +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 63AF77950;\n\tMon, 21 Jul 2025 21:13:06 +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=\"k9d0e4VR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753125186;\n\tbh=Ga3X20tI4gzh0yd/GubslVn3yarznfw3AHmIwGX6ERE=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=k9d0e4VRbyXXsl54jG+uT5SZr2++4C6DrBx67vnFFK/AQuWnbfxXhPVNWQUFMLvWV\n\tT6LFgQyijJfrOSN53TdpXy3mMyY7WpMXPp0UYTI9H7NOoLPInqtjdF0+n3t8YzSMhg\n\t5M65NBa+Qlrhz2/6S/Zw2PCSfBWzj/u08nPzauRA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240912051409.3495486-2-chenghaoyang@google.com>","References":"<20240912051409.3495486-1-chenghaoyang@google.com>\n\t<20240912051409.3495486-2-chenghaoyang@google.com>","Subject":"Re: [PATCH 1/1] libcamera: Put buffer back to V4L2BufferCache when\n\tVIDIOC_QBUF fails","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>","To":"Harvey Yang <chenghaoyang@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 21 Jul 2025 20:13:40 +0100","Message-ID":"<175312522037.50296.15209729881476131638@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>"}},{"id":34999,"web_url":"https://patchwork.libcamera.org/comment/34999/","msgid":"<175312614611.50296.6547875327712058723@ping.linuxembedded.co.uk>","date":"2025-07-21T19:29:06","subject":"Re: [PATCH 1/1] libcamera: Put buffer back to V4L2BufferCache when\n\tVIDIOC_QBUF fails","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Kieran Bingham (2025-07-21 20:13:40)\n> Quoting Harvey Yang (2024-09-12 06:09:39)\n> > From: Han-Lin Chen <hanlinchen@chromium.org>\n> > \n> > The patch puts buffer back to V4L2BufferCache when VIDIOC_QBUF fails\n> > in V4L2VideoDevice. This is to avoid cache leaks and causing assert.\n> > \n> \n> This seems reasonable - although could probably now be implemented in\n> less code with the new ScopeExitActions class which wasn't around when\n> this was posted I expect...\n> \n> However - while we could do a version with ScopeExitActions - I think\n> this is still correct *AND* fixes the error paths in\n> V4L2VideoDevice::queueBuffer() which are clearly leaking buffer cache\n> entries.\n> \n> So:\n> \n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n\nCI is green, so I'm very tempted to merge this already with the\nfollowing additional tag:\n\n\nFixes: cadae67e4578 (\"libcamera: v4l2_videodevice: Add FrameBuffer interface\")\n\nWhich is way back from 2019!\n\n\n\n> \n> \n> > Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n> > Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>\n> > ---\n> >  src/libcamera/v4l2_videodevice.cpp | 8 ++++++++\n> >  1 file changed, 8 insertions(+)\n> > \n> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > index 76742e18..75a2cdb1 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -1626,11 +1626,15 @@ 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> > @@ -1673,6 +1677,8 @@ 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> > @@ -1722,6 +1728,8 @@ 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> > -- \n> > 2.46.0.598.g6f2099f65c-goog\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 116E2C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Jul 2025 19:29:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6B58D69017;\n\tMon, 21 Jul 2025 21:29:10 +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 C947868FB1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jul 2025 21:29:08 +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 BF9F37950;\n\tMon, 21 Jul 2025 21:28:31 +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=\"LVqZD461\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753126111;\n\tbh=01eL/wyk8+B3wJhRCf+lGkjxId/rOWyJbOoZP+Ku3MY=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=LVqZD461xp/9q1dZ/JpPQDEwDP/5kucto2z3ABv7dOKXAnXGYXm1XLy2Q07ZRn+/C\n\tEhNK/D3Q3a2zUiwnb0HV5z8B275KQxX08+FHvIvj/+1Dky4ROpxOgKYY5jPdMcp2JL\n\tZAW7Rl1WtBlyP0l/x5utTg3B3rcU4sfEcMSB7pMU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<175312522037.50296.15209729881476131638@ping.linuxembedded.co.uk>","References":"<20240912051409.3495486-1-chenghaoyang@google.com>\n\t<20240912051409.3495486-2-chenghaoyang@google.com>\n\t<175312522037.50296.15209729881476131638@ping.linuxembedded.co.uk>","Subject":"Re: [PATCH 1/1] libcamera: Put buffer back to V4L2BufferCache when\n\tVIDIOC_QBUF fails","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>","To":"Harvey Yang <chenghaoyang@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 21 Jul 2025 20:29:06 +0100","Message-ID":"<175312614611.50296.6547875327712058723@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>"}}]