From patchwork Fri Jul 25 23:53:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23973 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 CD9D0C3237 for ; Fri, 25 Jul 2025 23:53:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CC2756910B; Sat, 26 Jul 2025 01:53:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UHTNJY1+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0DFC614C3 for ; Sat, 26 Jul 2025 01:53:17 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 8FFDC1387; Sat, 26 Jul 2025 01:52:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753487557; bh=5ZTWa97WQ/4ckUp3XRI6PgEK11FuWBe4gAALhFnMWV4=; h=From:To:Cc:Subject:Date:From; b=UHTNJY1+/yDRemb/E7+sXNmln6hn6l3JdVaEhKjI6KdJzy2T4LNj8ImzY9zv732qx gJJiRfGxhxePPWBleDO96uYq3mfSksUTFvmgkJagh1NOQxol3iV7CGBNfEcit63fck HokNUWM+pS9MF2EL2OxJNGwxuKjza4N6QimnJxK8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Han-Lin Chen , Harvey Yang Subject: [PATCH] libcamera: v4l2_videodevice: Use ScopeExitActions Date: Sat, 26 Jul 2025 02:53:11 +0300 Message-ID: <20250725235311.7280-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.1 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The V4L2VideoDevice::queueBuffer() function performs the same cleanup action in many error paths. Use ScopeExitActions to simplify it. Signed-off-by: Laurent Pinchart --- src/libcamera/v4l2_videodevice.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) base-commit: b65df7e7554b45e2d3d7fdb5b37c2ab7df3db4fe -- Regards, Laurent Pinchart diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 71cc7e895d8c..5f57e546e80b 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1646,6 +1646,7 @@ int V4L2VideoDevice::releaseBuffers() int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) { struct v4l2_plane v4l2Planes[VIDEO_MAX_PLANES] = {}; + utils::ScopeExitActions actions; struct v4l2_buffer buf = {}; int ret; @@ -1668,6 +1669,8 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) if (ret < 0) return ret; + actions += [&]() { cache_->put(buf.index); }; + buf.index = ret; buf.type = bufferType_; buf.memory = memoryType_; @@ -1683,15 +1686,11 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) */ if (planes.size() < numV4l2Planes) { LOG(V4L2, Error) << "Frame buffer has too few planes"; - cache_->put(buf.index); - return -EINVAL; } if (planes.size() != numV4l2Planes && !buffer->_d()->isContiguous()) { LOG(V4L2, Error) << "Device format requires contiguous buffer"; - cache_->put(buf.index); - return -EINVAL; } @@ -1734,8 +1733,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) if (i != planes.size() - 1 && bytesused != length) { LOG(V4L2, Error) << "Holes in multi-planar buffer not supported"; - cache_->put(buf.index); - return -EINVAL; } } @@ -1785,8 +1782,6 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) LOG(V4L2, Error) << "Failed to queue buffer " << buf.index << ": " << strerror(-ret); - cache_->put(buf.index); - return ret; } @@ -1798,6 +1793,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) queuedBuffers_[buf.index] = buffer; + actions.release(); return 0; }