{"id":17727,"url":"https://patchwork.libcamera.org/api/1.1/patches/17727/?format=json","web_url":"https://patchwork.libcamera.org/patch/17727/","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":"<20221028133847.12944-1-naush@raspberrypi.com>","date":"2022-10-28T13:38:47","name":"[libcamera-devel] libcamera: v4l2_videodevice: Guard against releasing unallocated buffers","commit_ref":"a2bdff6d0b67475492ac7cf9318866b6d89a28fd","pull_url":null,"state":"accepted","archived":false,"hash":"82a0c09a29239bf958251643cb701ec2541096e1","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17727/mbox/","series":[{"id":3586,"url":"https://patchwork.libcamera.org/api/1.1/series/3586/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3586","date":"2022-10-28T13:38:47","name":"[libcamera-devel] libcamera: v4l2_videodevice: Guard against releasing unallocated buffers","version":1,"mbox":"https://patchwork.libcamera.org/series/3586/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17727/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17727/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 15052BDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Oct 2022 13:38:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BD61462FE3;\n\tFri, 28 Oct 2022 15:38:53 +0200 (CEST)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C491661F4A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 15:38:52 +0200 (CEST)","by mail-wr1-x436.google.com with SMTP id bk15so6603766wrb.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 06:38:52 -0700 (PDT)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\th9-20020a05600c314900b003c6f3e5ba42sm7991323wmo.46.2022.10.28.06.38.51\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 28 Oct 2022 06:38:51 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666964333;\n\tbh=zNU/khhtKSDhOuxCzeKNATxmaq0nUz4jQcDMEWqDHNQ=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=1Pt2MzOLVLC6y6vo5HU8sy5C+LuLwYYgNJQNIDGxYHMUbB6tcnk7DE7rdJdpcMZj4\n\tgPvUsgyX4WIXmn089QOevkdCqdQCeGk3SjUhnSb1B6+ey/60bVXmf17JxIIo2/X9p6\n\tSdEl2slakE0jB4IcmGsgda0LiiOzj0lLDF8vmv4TRdHMoaqgqyEYvwBXtQKFq4J2Po\n\tytM6nnmt1le546YtkruoDH9X+arEDPLVBHWfFeRVhnj9+qZijxo6KtF+s9cQEGcTq0\n\tnJ36VVpJdtfgvDMMATU+/u0i7d8aAYEhzHmhZFsX5U7RV71HBLYcnh+dta1XMfM+6R\n\tDMMG+mf84HOTg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=yPIq4+chN4YmA/6G0cca91zgkXgIE7BUB7V+Fe8Lvvo=;\n\tb=VEJIhRuaozRoD+I9wMsyMGDXgfUzfD+txNhA1YJVm68zhy8qji0Hw1jLtg+prQNso9\n\t9G1KCSHgX/H3zeoTYeGVF/6Nqpkw2MWGEsUB+KFG64wPG2wsWNLVR8hHRWbwO4wTChAI\n\tewIlTD6rSWdAvhRh3Y787FJhulDf9/FT6MM5fcjRDCbfCNNvy0ZTFauyKGNzmOa7ce6r\n\tpAdZjuzPtWC7eVywaehsVhczlzd3nH9eFfbGdiY+RhTSaNfvpY3GjXtzO+5tXW7uqa7X\n\t3d4x+iqeVt6tg3qRw7Gb62hEobgY8/E6QME3bIzFN8OK/VodkMTaliVrFNNRc+319POp\n\tM/iQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"VEJIhRua\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=yPIq4+chN4YmA/6G0cca91zgkXgIE7BUB7V+Fe8Lvvo=;\n\tb=wVXlM5A6+xsfmw4TgiHbKLPH9/RHSp7EwCkefaltb3xMAPYB2FLhNeCWAu+cPGe73b\n\toJz37e9Xbomr49lbAOLFMKhlgUG1IzOMXts8EJsbldqUyA8fCQ/eISde5NbmCEVh4Ux+\n\t3or2q41xR3f5pRrg6l7nhcey39g6wqjVeAEdp6Fq1vdGbZaWdl0bhP4GPL6MEDTKch3U\n\taNOfBn/Ra0BX5GEVusfpT8mLiwbPjGQOwBQxkC2UmcpVj6uoUewYTkSS4bphm2ImtAQs\n\t8laQijKPP2md3wommcR8OM1MOVBByr100BJjc/ZA9+D/YjnllYjzgHhjjusxHeEHWFhv\n\tdRBg==","X-Gm-Message-State":"ACrzQf0nbr/AyLTPnlNv9eyzKKlAfZQg7AVvvQAiTgKn3xfJhmNHYBSv\n\tcjN/mlvrgA7JlOe4+aug3ZuM4pQNPHtHxA==","X-Google-Smtp-Source":"AMsMyM7H8+7coolNzBGuOI8iKeewY4TyQJpNxr/ustn8wi0bs5pyx+1wpfmF9VeFucy049nZ83R+Rw==","X-Received":"by 2002:a5d:5610:0:b0:236:50d5:e6ec with SMTP id\n\tl16-20020a5d5610000000b0023650d5e6ecmr26078982wrv.13.1666964332096; \n\tFri, 28 Oct 2022 06:38:52 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 28 Oct 2022 14:38:47 +0100","Message-Id":"<20221028133847.12944-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20221028115200.8138-2-naush@raspberrypi.com>","References":"<20221028115200.8138-2-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[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":"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>"},"content":"releaseBuffers() unconditionally calls ioctl(REQBUFS, 0) to release device\nbuffer allocations through the close() and class destructor functions. If\nanother libcamera process is running concurrently with a different sensor, it\nwould cause the ioctl to fail in the kernel because the buffer queue is owned\nowned by the other process. This in turn would cause libcamera to generate an\nerror log message.\n\nFix this by ensuring the releaseBuffers() only calls ioctl(REQBUFS, 0) if there\nhave been buffers previously allocated by the device. This is done by testing\nthe presense of the V4L2BufferCache in the object.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/libcamera/v4l2_videodevice.cpp | 3 +++\n 1 file changed, 3 insertions(+)","diff":"diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 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+\tif (!cache_)\n+\t\treturn 0;\n+\n \tLOG(V4L2, Debug) << \"Releasing buffers\";\n \n \tdelete cache_;\n","prefixes":["libcamera-devel"]}