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_; From patchwork Fri Oct 28 11:52:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17726 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 353CABDB16 for ; Fri, 28 Oct 2022 11:52:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C94D862FDE; Fri, 28 Oct 2022 13:52:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666957928; bh=RdU01E7m/mPlZLCGKkhVgezt0HUMZDaZhZcV/C16tAc=; 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=EnWrMtLtcKNVA2p9neMtEVT8A8pcXNNkE+bTx0gQ8vt62Ba+q9kWG/PLTJUvjkJwq vMiOT7smsIpbDEmRdFSgDctto6A7z0VjhrceAwXjf+6t1K+1iRXhITvqDJthAHB2y8 nPW0rd2kBLOn735J0xFmiBwXceeFXu7gtbCWBIi0Wc84ogbFh29whZQbpJmstX28Iv wYNdjutahEErdy9XFeqpXhDcFpWfMs379PRpRbjkuMa40Zd9RsiKRwzIoyAHHU7LQN V13L6Tcj6zlUQ6w9rh85WmD88vS0fJh8ysVs/HYa/pE4c71XIRTR5I8eg975yOK8kr 6Zd5cIceHI/Uw== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 234BB62FD5 for ; Fri, 28 Oct 2022 13:52:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qIZC9NcE"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id b20-20020a05600c4e1400b003cc28585e2fso3669369wmq.1 for ; Fri, 28 Oct 2022 04:52:06 -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=5AiDnYESq1STHI/2ycKsedI2/UnLEEdz3AN1E5rBL5E=; b=qIZC9NcEfk0IxGRJAziXtl6lmOtPfX5TXPm11kQ9NVoMGYuXSZCJ9uSZ2jr+Go09MP yFkHiTXiqRss3CpFRIBSr1Hed+LnATQ+A6z6j2K6QZf1nGFU7Mhwaf5BlR0mwlF9BF/W TXmCbh/akbJyfxGBtsFGEDNjDpqksy95+qqqrTIBRnAXKF2MzwqWD+oP8hn2G4L4F1Yy nN9xclZXv1motUHMYALb/6bdfAe5IGhzjgNJmEG+NPk9zhFgCU1aZguYmSSe7KOdLvHo A2wNg4DNGHfj7+URG84vfW48oQVntG9xleczBUUib6x5eioi7q53I7IdZS2VeLMvGhfu yxMQ== 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=5AiDnYESq1STHI/2ycKsedI2/UnLEEdz3AN1E5rBL5E=; b=PEJkRkfgFI5BNQcrb7bynO0B1Dne+Xwdg/+0syeHGzgLL6EnC+2+jEI7GaSe63hbtW zrwsTeZLLSfM2jlISFma9aJcIF7XZqW2fe2iUNwFO8f4N5xhZOnrjNqYfnoLVdBgRWoH ufYzxlbi6h7KfYybRxrHEKNMJBS9Mbqi40W8sGW2eY2ugIMW48Znkhn5lHy2IC4PiXEk kTHlRqQ/Qh05Oj4tX4c7nTE2s8h61OA/DYBMhm8JELTSjpY8y/uNpEad7WzVVpMnXfbf Xh2zs0vYyaIVG4B4RR1GgSux7tPJ89RXPyNpgb2cyPIzZ/OiKS3wUUhpNxzsOGXirQBu YHOw== X-Gm-Message-State: ACrzQf2/anQheStILBoibR0rRA6flpUZUETbZhlDanz2GsWgwCCPdgc1 JXmBCXKNnccUKwJsU8QlHlFz2tacyE9uXw== X-Google-Smtp-Source: AMsMyM64n8mWu9XaF0LfVVmh7PGFfOZmAY+iEojqQ0+HTRxKNgLLzDxTaYV956+m3ib8H9xeau7HMg== X-Received: by 2002:a05:600c:35cb:b0:3c6:e382:62fb with SMTP id r11-20020a05600c35cb00b003c6e38262fbmr8991671wmq.22.1666957925345; Fri, 28 Oct 2022 04:52:05 -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.04 (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:52:00 +0100 Message-Id: <20221028115200.8138-3-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 2/2] pipeline: raspberrypi: Do not unconditionally free buffers on close 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" When a camera is terminated, do not unconditionally free buffers in the RPiCameraData destructor. Otherwise, this causes harmless error log messages to be displayed if no buffer have previously been allocated. Signed-off-by: Naushir Patuck Tested-by: David Plowman Reviewed-by: David Plowman Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 343f8cb2c7ed..31107e1338bf 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -191,7 +191,8 @@ public: ~RPiCameraData() { - freeBuffers(); + if (buffersAllocated_) + freeBuffers(); } void freeBuffers();