[{"id":25670,"web_url":"https://patchwork.libcamera.org/comment/25670/","msgid":"<CAHW6GYK7TFtFKvpTkna5mXPhtfcBZdD+p-83P5=MJXUZO-ocJA@mail.gmail.com>","date":"2022-10-28T13:40:37","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Guard\n\tagainst releasing unallocated buffers","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for the update!\n\nOn Fri, 28 Oct 2022 at 14:38, Naushir Patuck via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> releaseBuffers() unconditionally calls ioctl(REQBUFS, 0) to release device\n> buffer allocations through the close() and class destructor functions. If\n> another libcamera process is running concurrently with a different sensor, it\n> would cause the ioctl to fail in the kernel because the buffer queue is owned\n> owned by the other process. This in turn would cause libcamera to generate an\n> error log message.\n>\n> Fix this by ensuring the releaseBuffers() only calls ioctl(REQBUFS, 0) if there\n> have been buffers previously allocated by the device. This is done by testing\n> the presense of the V4L2BufferCache in the object.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nTested-by: David Plowman <david.plowman@raspberrypi.com>\n\nThanks!\nDavid\n\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 3 +++\n>  1 file changed, 3 insertions(+)\n>\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index e30858c9fa02..0d60dbd1c23d 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1533,6 +1533,9 @@ int V4L2VideoDevice::importBuffers(unsigned int count)\n>   */\n>  int V4L2VideoDevice::releaseBuffers()\n>  {\n> +       if (!cache_)\n> +               return 0;\n> +\n>         LOG(V4L2, Debug) << \"Releasing buffers\";\n>\n>         delete cache_;\n> --\n> 2.25.1\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 3AA34BDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Oct 2022 13:41:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 91F5A62FE3;\n\tFri, 28 Oct 2022 15:41:01 +0200 (CEST)","from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com\n\t[IPv6:2607:f8b0:4864:20::1036])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CB79D61F4A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 15:40:59 +0200 (CEST)","by mail-pj1-x1036.google.com with SMTP id\n\tc15-20020a17090a1d0f00b0021365864446so4497806pjd.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 06:40:59 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666964461;\n\tbh=x3ZFWS7bD70/pUngrQt3HwOOuD2Fs0YzVvUpLGIWA0o=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=qF8njFo6EKlYgbOFhOliyM39rtyBiqEd/ao4JWf/LtvoQ4Y7XvK0w5Aclo3dY0I4M\n\tnUs1F8iCM2K++cf/bPatXHawI++Nk7Nqr217derlYhACLFhM3wxGzefKHnSYDwsuKl\n\tVRZ4oZ9iKto/cRm5E6lEbLd06TXcsUpFUwuEyHF5qy5xwBVVbcZUM/RGG/edOmOqE6\n\tor/20Dv+EkvvpCAfEJk3MAKZLXa2d9ScryJDXfkmYLfAR4TOeHKxuG7gtvRbjiKNT5\n\tKvXbh3VCnwRQYMZrFfGNjCTQRaDMasF4TxGPBjkH1fTbcLDtzwrVSfC7cdDyo21lpt\n\tZfi5ZPZwiz/JA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=gbr9cha3qqaRpYSGcRCu2sEfxwmeUr4WWsT36IwSd68=;\n\tb=QcOO8sw8CAeAskSg3HWHTHXPnrzkEyOuFtmArc6tpTcIYurYuJRcsxHoA8+Vz76xqR\n\tmHusQgVobidqJyRlsrVpNZSOel6sCvGM1uCKV5th3gYAli33E+10FltUAiqfTqGdtR3F\n\tt5lJ+CTaVzKWKfGlHrHkR7qg3H0BGhizsyMt/EsW9ZyW6IxPwtfcUwzSvpfs7agn/KE4\n\tXcgvdqvzVtVnQVRubb2s5uHviYsz3jB5e9gxEIgJt6hwsyTPue/YGn0UxDiJjsjFAHan\n\te6I01ryQSh7bLRXcjfc+AO6wkc7oAV4RQfyvzc/DjGyx1ojvVudecQNUroq8tdgPhiGP\n\teHBg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"QcOO8sw8\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=gbr9cha3qqaRpYSGcRCu2sEfxwmeUr4WWsT36IwSd68=;\n\tb=cDJ0zt8itJfw0wJn7zexGGXDcHYOrgUXzCTHlH0q+KgwVmW4t/9SN+eLF7hJowTF39\n\tr3L66MH/th4ZM46i2cOvL/8TGra924ew4rUOusblHmr9AsrInWnV1UlJUh6/zTvwIHux\n\tKZfH9+llRzkoIlfXZ/FbvQclre9Ouh0YJEOfIw5hrRAcWBpRaHGDCSCeKh8PgE3VrjOv\n\t5ulz/AAa1CvAXaHj9S9ZC2WJ3fecLCczkyzP3f6YtBcKIWNoMAMCbetsjSM+7DoVTEjp\n\tRRntKzB+4jYP8MZWCqJb09flYfUBQueOx1OGsuMpUgTXQFGYgz9cMwKRr4OK9GzoGyAE\n\taf5A==","X-Gm-Message-State":"ACrzQf0Ty7nBHqxP+eU6tXkUc5racwo6M2NjgaKe5wOnLCDNKAgsXrEn\n\tTUPVqmXSkTLt5LIA/yAe1iCbDvWjw9d8knT6Wz+J/pdVGjQ=","X-Google-Smtp-Source":"AMsMyM4qcAiM9vVzTfVm5b6GR9INfWeYPqlHJXRPLIbGrqWBuA9MecMNZBSZzwPQQD6uD0ydSTsKaqIY3qvt9PAM4pA=","X-Received":"by 2002:a17:902:f54d:b0:185:4ca4:2641 with SMTP id\n\th13-20020a170902f54d00b001854ca42641mr53805495plf.50.1666964448158;\n\tFri, 28 Oct 2022 06:40:48 -0700 (PDT)","MIME-Version":"1.0","References":"<20221028115200.8138-2-naush@raspberrypi.com>\n\t<20221028133847.12944-1-naush@raspberrypi.com>","In-Reply-To":"<20221028133847.12944-1-naush@raspberrypi.com>","Date":"Fri, 28 Oct 2022 14:40:37 +0100","Message-ID":"<CAHW6GYK7TFtFKvpTkna5mXPhtfcBZdD+p-83P5=MJXUZO-ocJA@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Guard\n\tagainst releasing unallocated buffers","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>","From":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":25671,"web_url":"https://patchwork.libcamera.org/comment/25671/","msgid":"<166696453389.15935.637081315022999824@Monstersaurus>","date":"2022-10-28T13:42:13","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Guard\n\tagainst releasing unallocated buffers","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck via libcamera-devel (2022-10-28 14:38:47)\n> releaseBuffers() unconditionally calls ioctl(REQBUFS, 0) to release device\n> buffer allocations through the close() and class destructor functions. If\n> another libcamera process is running concurrently with a different sensor, it\n> would cause the ioctl to fail in the kernel because the buffer queue is owned\n> owned by the other process. This in turn would cause libcamera to generate an\n> error log message.\n> \n> Fix this by ensuring the releaseBuffers() only calls ioctl(REQBUFS, 0) if there\n> have been buffers previously allocated by the device. This is done by testing\n> the presense of the V4L2BufferCache in the object.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 3 +++\n>  1 file changed, 3 insertions(+)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index e30858c9fa02..0d60dbd1c23d 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1533,6 +1533,9 @@ int V4L2VideoDevice::importBuffers(unsigned int count)\n>   */\n>  int V4L2VideoDevice::releaseBuffers()\n>  {\n> +       if (!cache_)\n> +               return 0;\n\nReturn 0 looks like it will keep the compiler happier than return;\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n>         LOG(V4L2, Debug) << \"Releasing buffers\";\n>  \n>         delete cache_;\n> -- \n> 2.25.1\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 D0C05BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Oct 2022 13:42:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9CC7B62FE3;\n\tFri, 28 Oct 2022 15:42:17 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6937961F4A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 15:42:16 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 063516BE;\n\tFri, 28 Oct 2022 15:42:15 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666964537;\n\tbh=Izr6bdWgefEGd54rEpRy0EdSvn2WNf7pfuJG6PH/III=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=0GFJJAtq85UIRwQkQssxqs2T200jVHL44933UXHzqX6tdZyvkinXt9jUfXUe5b3hI\n\tWgZtSxPQnYDWD24e41D+GhpvQpjo2e1mEh7gg0vqJXZnpZdMTorzLXU+1k3ijR51gu\n\tmV5dnVXA8iTGqtmLv1f8cy9uWCCWzDu88/zj4aBabcqcrrtomKSn2SQtm/dLtX1zmW\n\tpM8wabtyVvNrhJupC2oolK6TuxEN3oq4zEsGP7gVn5RAUFwVELbdGeVsEfzZ3qfFPH\n\tlz4FnOLhwqiBIwpSS8dc42lBnTcvq3cXXqzYRqoO6eSSh0e12oBiBwT3pCh7CiD+Ix\n\tRv1CH17UYkgSg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666964536;\n\tbh=Izr6bdWgefEGd54rEpRy0EdSvn2WNf7pfuJG6PH/III=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=p90dnKn8MZxLd+xL9IGt4okycyOiridTPN6cp3iwUnNoGJpuAATfzxYmpTap3poGO\n\t2s7bGBtSaZbMkzijSHiqg9bNbhodl8rcBxB1TbnIzn4i1+jsdpNT6wo1SC8RuW+StP\n\tcAAYRrj7IzDij8fBISENesufXwG5Xh8Z2wKlmPXM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"p90dnKn8\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20221028133847.12944-1-naush@raspberrypi.com>","References":"<20221028115200.8138-2-naush@raspberrypi.com>\n\t<20221028133847.12944-1-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 28 Oct 2022 14:42:13 +0100","Message-ID":"<166696453389.15935.637081315022999824@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Guard\n\tagainst releasing unallocated buffers","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]