From patchwork Mon Jan 20 14:16:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22586 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 3D4C9C327D for ; Mon, 20 Jan 2025 14:17:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3455968550; Mon, 20 Jan 2025 15:17:08 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="gXqdqdVR"; dkim-atps=neutral Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A627684E4 for ; Mon, 20 Jan 2025 15:17:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1737382625; x=1737641825; bh=EZ15LKxgYPOmqH+IXimN7zAbu3/pPkDM2jnFknmmCp4=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=gXqdqdVR/Y9oPdOsi2lgWrl46qQA78HQ2E06vT4URrMAQBIZd06hB7E86JwmAhRQX 8LVNzyeneXhdAZIC+Z4WZmOTeTfiB1tBZHgQlNkICV2TEEocMPAvjeup2k50dhuoQ9 aIRHsDRnJkz0RsSl7EU2POo37wNu/XRIry2Ytu9zIAiNAP2km4l8xE+pT66i4xks6u TrYPTgmiKxOegQTmNCMzw22ADGC+qbjXpHVsTqR2gtL0rYETEIaMWCcKgye0jMhIMS ZJ0P0rysyK/HPSxtExahPgilVp9hLFlc5h6Th0CW829fyYgv/fAPRNUMQlei44Olje +/QpgeALQdjOg== Date: Mon, 20 Jan 2025 14:16:59 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1] libcamera: request: addBuffer(): Do fence check earlier Message-ID: <20250120141657.95664-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 741dfc6fc2438c2abc09ff8bb1baa0e8355c394f 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" Check if the buffer has a fence before making any modifications because otherwise it is possible for `Request::addBuffer()` to return an error code while at the same time the buffer - for all intents and purposes - is added to the request. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/request.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 5cfafea89..e7eb1c0c8 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -466,6 +466,15 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer, return -EINVAL; } + /* + * Make sure the fence has been extracted from the buffer + * to avoid waiting on a stale fence. + */ + if (buffer->_d()->fence()) { + LOG(Request, Error) << "Can't add buffer that still references a fence"; + return -EEXIST; + } + auto it = bufferMap_.find(stream); if (it != bufferMap_.end()) { LOG(Request, Error) << "FrameBuffer already set for stream"; @@ -476,15 +485,6 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer, _d()->pending_.insert(buffer); bufferMap_[stream] = buffer; - /* - * Make sure the fence has been extracted from the buffer - * to avoid waiting on a stale fence. - */ - if (buffer->_d()->fence()) { - LOG(Request, Error) << "Can't add buffer that still references a fence"; - return -EEXIST; - } - if (fence && fence->isValid()) buffer->_d()->setFence(std::move(fence));