From patchwork Fri Oct 28 13:38:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17727 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 15052BDB16 for ; Fri, 28 Oct 2022 13:38:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD61462FE3; Fri, 28 Oct 2022 15:38:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666964333; bh=zNU/khhtKSDhOuxCzeKNATxmaq0nUz4jQcDMEWqDHNQ=; 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=1Pt2MzOLVLC6y6vo5HU8sy5C+LuLwYYgNJQNIDGxYHMUbB6tcnk7DE7rdJdpcMZj4 gPvUsgyX4WIXmn089QOevkdCqdQCeGk3SjUhnSb1B6+ey/60bVXmf17JxIIo2/X9p6 SdEl2slakE0jB4IcmGsgda0LiiOzj0lLDF8vmv4TRdHMoaqgqyEYvwBXtQKFq4J2Po ytM6nnmt1le546YtkruoDH9X+arEDPLVBHWfFeRVhnj9+qZijxo6KtF+s9cQEGcTq0 nJ36VVpJdtfgvDMMATU+/u0i7d8aAYEhzHmhZFsX5U7RV71HBLYcnh+dta1XMfM+6R DMMG+mf84HOTg== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C491661F4A for ; Fri, 28 Oct 2022 15:38:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="VEJIhRua"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id bk15so6603766wrb.13 for ; Fri, 28 Oct 2022 06:38:52 -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=yPIq4+chN4YmA/6G0cca91zgkXgIE7BUB7V+Fe8Lvvo=; b=VEJIhRuaozRoD+I9wMsyMGDXgfUzfD+txNhA1YJVm68zhy8qji0Hw1jLtg+prQNso9 9G1KCSHgX/H3zeoTYeGVF/6Nqpkw2MWGEsUB+KFG64wPG2wsWNLVR8hHRWbwO4wTChAI ewIlTD6rSWdAvhRh3Y787FJhulDf9/FT6MM5fcjRDCbfCNNvy0ZTFauyKGNzmOa7ce6r pAdZjuzPtWC7eVywaehsVhczlzd3nH9eFfbGdiY+RhTSaNfvpY3GjXtzO+5tXW7uqa7X 3d4x+iqeVt6tg3qRw7Gb62hEobgY8/E6QME3bIzFN8OK/VodkMTaliVrFNNRc+319POp M/iQ== 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=yPIq4+chN4YmA/6G0cca91zgkXgIE7BUB7V+Fe8Lvvo=; b=wVXlM5A6+xsfmw4TgiHbKLPH9/RHSp7EwCkefaltb3xMAPYB2FLhNeCWAu+cPGe73b oJz37e9Xbomr49lbAOLFMKhlgUG1IzOMXts8EJsbldqUyA8fCQ/eISde5NbmCEVh4Ux+ 3or2q41xR3f5pRrg6l7nhcey39g6wqjVeAEdp6Fq1vdGbZaWdl0bhP4GPL6MEDTKch3U aNOfBn/Ra0BX5GEVusfpT8mLiwbPjGQOwBQxkC2UmcpVj6uoUewYTkSS4bphm2ImtAQs 8laQijKPP2md3wommcR8OM1MOVBByr100BJjc/ZA9+D/YjnllYjzgHhjjusxHeEHWFhv dRBg== X-Gm-Message-State: ACrzQf0nbr/AyLTPnlNv9eyzKKlAfZQg7AVvvQAiTgKn3xfJhmNHYBSv cjN/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 l16-20020a5d5610000000b0023650d5e6ecmr26078982wrv.13.1666964332096; Fri, 28 Oct 2022 06:38:52 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h9-20020a05600c314900b003c6f3e5ba42sm7991323wmo.46.2022.10.28.06.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 06:38:51 -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 Subject: [libcamera-devel] [PATCH] 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 Tested-by: David Plowman Reviewed-by: Kieran Bingham --- 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..0d60dbd1c23d 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 0; + LOG(V4L2, Debug) << "Releasing buffers"; delete cache_;