[{"id":25669,"web_url":"https://patchwork.libcamera.org/comment/25669/","msgid":"<CAEmqJPqLxdUkEczPqvPri9ZvtXoeX64xQ7r0npj1tQCd6Od-RQ@mail.gmail.com>","date":"2022-10-28T13:37:38","subject":"Re: [libcamera-devel] [PATCH v1 1/2] libcamera: v4l2_videodevice:\n\tGuard against releasing unallocated buffers","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Apologies!  This was not meant to be the patch I wanted to push.  My brain\nhas shut down for the weekend.\nI'll push an update for the correct patch in reply to this one.\n\nNaush\n\n\n\nOn Fri, 28 Oct 2022 at 12:52, Naushir Patuck <naush@raspberrypi.com> 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,\n> it\n> would cause the ioctl to fail in the kernel because the buffer queue is\n> owned\n> owned by the other process. This in turn would cause libcamera to generate\n> an\n> error log message.\n>\n> Fix this by ensuring the releaseBuffers() only calls ioctl(REQBUFS, 0) if\n> there\n> have been buffers previously allocated by the device. This is done by\n> 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\n> b/src/libcamera/v4l2_videodevice.cpp\n> index e30858c9fa02..ed446c25e45f 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\n> count)\n>   */\n>  int V4L2VideoDevice::releaseBuffers()\n>  {\n> +       if (!cache_)\n> +               return;\n> +\n>         LOG(V4L2, Debug) << \"Releasing buffers\";\n>\n>         delete cache_;\n> --\n> 2.25.1\n>\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 5F0ECBDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Oct 2022 13:37:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1490B62FE7;\n\tFri, 28 Oct 2022 15:37:56 +0200 (CEST)","from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com\n\t[IPv6:2607:f8b0:4864:20::f29])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F1D9C61F4A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 15:37:54 +0200 (CEST)","by mail-qv1-xf29.google.com with SMTP id ml12so4091966qvb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 06:37:54 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666964276;\n\tbh=Kh+7vukZqa38zxHyhfayAh67DyDvFCdSgt2r8rst6QQ=;\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:\n\tFrom;\n\tb=XRs9weiV+Eb61meK11yyio9F5SrikB6M1fQ3dq2D6gyhkFnYJ0Cy4oIu4yEc9hQTq\n\twweUnKupSDI4aQOeL2n7RlMwr2nByyGwVl0/UI6IDjLlqF9C3v5/IhwUtWYbTxZldc\n\txaPIX8noSwesltTG8dTNbglNC/WJGMoi5N+3EUOSstaJkyom319gD9SJjbXCtvlwog\n\thBSkqs448o8Qss+cJBu3SSP8tLrcCiHwXg5RNwhz0BTJtSeRJYUTASLII5ZdKRW/5r\n\tMfGKo05gVQyXy+/vce7xMBqZCyLxDGvw+1o1yL+ehw5Gm3iCdeOBLlVZEp9UQ2QLo4\n\tZgHV8piTf44Ug==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=to:subject:message-id:date:from:in-reply-to:references:mime-version\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=d/flSUYHyoQH9u/JbJmj4cqML9etJrcsNhoOpphZlqk=;\n\tb=fMBcYZ4RvneNePc0PloiMnQF3k9m3OGygzDKFvO8yD8Wkg2w7x37rJGR07NdEtDBr5\n\t8d/hnXzF4K++qbe2icAxvtA7H0zhCKaiTSpAvHj/xbS77FOwyQ8XGHUMi0XdvwZ1ulBe\n\tjCTajrM+hV5myTdtJM5IaUu/pHMQbBP8qqwe6cgl/9md92Sd60Jmx5LA5ZT1CaDmPp6n\n\tHmeMhEVFs5jc+Z3wFZprR2mQ0UEiDX/nZbVe7wuP+/otYIcBVKpcHrMqHfW477ywf/sd\n\tzBexgWzEarGBDj/fSA9atRhlpKPqQLp1gIulBoxE6ORxdjDMAwXOww97APiKBVto1+aN\n\tAlvw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"fMBcYZ4R\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=to:subject:message-id:date:from:in-reply-to:references:mime-version\n\t:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\n\tbh=d/flSUYHyoQH9u/JbJmj4cqML9etJrcsNhoOpphZlqk=;\n\tb=PrBAjA8tJ1PSke45xuCSv/SuNrqOphhn+ECiWpsYPzdpKSVeCjtJGyddS0QnMhOJNy\n\tXojgy3HcHIVeKMpAvx8qn/hUOMHvfIc81AE8Q+wiu1zUsHW9OGep+RWmgAe7ZuD7Awo0\n\tezv7oHl6j61chryerAlhuZzDOulIbrUX/xqvEbO0iggWgUATnk5ZrPfqQwwLSgJJ+RfB\n\tO4HlMPMIKp2YoIp+iqz/MNy1Uub31GmEnBGitedVR2Cr6AxG4qW75Uayf/UQW1/UZ/gk\n\ttuVLdwomOFiZ2Effuj50qjQ6HAnMPomNA0mnIqtnCDOfuKg511+ASFNRBp2HKETRrGSI\n\tt9VA==","X-Gm-Message-State":"ACrzQf3JtbsHrRxP5YGVc8EWQcU58VDlyqIUH8zQJ8flqboYXyyyBFMe\n\tMsdMj9vt+gtE7oCynTFzuwbfJE693BdqlFsSGM7Dzjv8bXQ=","X-Google-Smtp-Source":"AMsMyM6LPwCnJjGXfXBOWB9f5EPvkJe7amV4jOshOQ0a2bCR5TR+wg/rcGOc46b4clPvMwPO3PHu0wTNeD/ssB6AnAQ=","X-Received":"by 2002:a0c:cb90:0:b0:4bb:a808:4485 with SMTP id\n\tp16-20020a0ccb90000000b004bba8084485mr5833914qvk.101.1666964273658;\n\tFri, 28 Oct 2022 06:37:53 -0700 (PDT)","MIME-Version":"1.0","References":"<20221028115200.8138-1-naush@raspberrypi.com>\n\t<20221028115200.8138-2-naush@raspberrypi.com>","In-Reply-To":"<20221028115200.8138-2-naush@raspberrypi.com>","Date":"Fri, 28 Oct 2022 14:37:38 +0100","Message-ID":"<CAEmqJPqLxdUkEczPqvPri9ZvtXoeX64xQ7r0npj1tQCd6Od-RQ@mail.gmail.com>","To":"libcamera-devel@lists.libcamera.org","Content-Type":"multipart/alternative; boundary=\"0000000000006293fa05ec185d20\"","Subject":"Re: [libcamera-devel] [PATCH v1 1/2] libcamera: v4l2_videodevice:\n\tGuard against 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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]