From patchwork Fri Oct 28 11:51:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17725 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4993FC3285 for ; Fri, 28 Oct 2022 11:52:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6DE3862FD7; Fri, 28 Oct 2022 13:52:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666957926; bh=cMfI4eFnCXgAVzc0Q4WC2zWs21d3htd644CLmrZOmi4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=z8lGT+1ykszJw3n5+z2GVDFmH2EsrwaduSwZH0Kt0aRZjLlWmfSCDBYxXpj7gEy3e r8vgbOrYELxDXhXm5o2Mq679mSdX02X41/TB5NoE15NXPPHRborBihUXtXCb7LSU5x dFYsFkOiskRCQc+ObLjFi6+35Gmshh4rV+gW+60I9vgEciTyhT0+IEN8LFgbZIj++M dP0DTTtcA1BuvgPyAi2XPYV2KGAAqU4BRhNBeVp9ti1PO7Hztlzh8jPp9Eq9PfeS/9 LvxTWs+YZPAcM+f3BYICeBXZau6A5xPU1lG1pXNOw55Wt+kZ0eJWhWYbAUjQeWlajx cKSMWxMBbq3oA== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2FA7B61F4A for ; Fri, 28 Oct 2022 13:52:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="HvYbNGL/"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id i5-20020a1c3b05000000b003cf47dcd316so6444738wma.4 for ; Fri, 28 Oct 2022 04:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VYUNz4rxyQseG9GQx4W+HnN+aeqxFCgBIu6OdPykKlQ=; b=HvYbNGL/r1CAD7b69+NRNBPRxdGy+Qs9QkbsoQXKHwru4AdjdtLjor5SeYn9AIjwVx 3+89wfsiPMw77gxYC97wNqkdRBJ0HIe/0zuGVt037IkJn3erZVFCM2pPeUZQKtfaKAVS 0FsuZOlCUxJ3nf4rUNhVmPUWdVadD6gBCzRYDs2W8Ra7ETB4psrY0kLtkOpxFUkBGLMD L+ARGMG/xiSg+N0yzXsmkxBksNJm5aNySj93RtT/+9Pny8BvSZjnFNJtRM2jS859vjD7 wN6hUvRxjAaYqHY4q8E9KeVp3uW/QE9v0pRgtR+IBxGAX9DTT3SADzusYmkjE5S+Y3/b UWBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VYUNz4rxyQseG9GQx4W+HnN+aeqxFCgBIu6OdPykKlQ=; b=kxPtUimmnurK073PtfPj48VvsgBDMiSGUdHBAJUIPS+VcXRMHIWLOxOQd/7tsGzQr0 N81W6j4uYJMBNkYSFGjwQjdF24y6PX6D2pRsrPuf0H8433RWSom2VRlVSE2KX+ZlJ6Hc cxXK3oIMf+JG1lO5Yd06MpMavFQDd+2pvJcYJF3AxWcQb6H4xTxsVixW4nYJhdHlQ7nR s8L2EZLb0hxqsZNdxPmwkTwteugntLjLJZTFBvDRC8F8lGQKuW+mEiLWEd81RuJ3N1EX 71AAvLI+qt9Wm9svCcO6h47LDcKnvphvXJbMVznNzAYzPCTzaOuebAs6MQgjW9pOkGB/ 2BAw== X-Gm-Message-State: ACrzQf3CvIB3IEPXXUI86mzHxs92Mubh4FnRx3s6BltTNx25i3392VbE 8/ZSy1DMRAMLXEpDKnqvPHHTbDVKlWAWTw== X-Google-Smtp-Source: AMsMyM7MLijwbnw3BjiT0eEf3x/5M9pMRwFtYswI2kJbCfrexKPiAxQc71M4lYTiSyXCshzjxe4MgQ== X-Received: by 2002:a1c:2987:0:b0:3c6:c0cc:b4c2 with SMTP id p129-20020a1c2987000000b003c6c0ccb4c2mr8963366wmp.56.1666957924533; Fri, 28 Oct 2022 04:52:04 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id a5-20020adffb85000000b002366fb99cdasm3441686wrr.50.2022.10.28.04.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 04:52:04 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 28 Oct 2022 12:51:59 +0100 Message-Id: <20221028115200.8138-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221028115200.8138-1-naush@raspberrypi.com> References: <20221028115200.8138-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/2] libcamera: v4l2_videodevice: Guard against releasing unallocated buffers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" releaseBuffers() unconditionally calls ioctl(REQBUFS, 0) to release device buffer allocations through the close() and class destructor functions. If another libcamera process is running concurrently with a different sensor, it would cause the ioctl to fail in the kernel because the buffer queue is owned owned by the other process. This in turn would cause libcamera to generate an error log message. Fix this by ensuring the releaseBuffers() only calls ioctl(REQBUFS, 0) if there have been buffers previously allocated by the device. This is done by testing the presense of the V4L2BufferCache in the object. Signed-off-by: Naushir Patuck --- src/libcamera/v4l2_videodevice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index e30858c9fa02..ed446c25e45f 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1533,6 +1533,9 @@ int V4L2VideoDevice::importBuffers(unsigned int count) */ int V4L2VideoDevice::releaseBuffers() { + if (!cache_) + return; + LOG(V4L2, Debug) << "Releasing buffers"; delete cache_;