From patchwork Mon Nov 23 17:47:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 29076 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 85FA7C3355 for ; Mon, 23 Nov 2026 17:47:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9BDC76A9B2; Mon, 23 Nov 2026 18:47:26 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OU3jvMFm"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 29B346A99E for ; Mon, 23 Nov 2026 18:47:21 +0100 (CET) Received: from ping.linuxembedded.co.uk (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ED401E91; Mon, 23 Nov 2026 18:44:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1795455889; bh=nlYQa/LSptvOSpsvBjZuz2GBY7Wt6zbCGGPqzgK8B04=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OU3jvMFm61RrjrdRs43b09jg6tbn+lQH1Zyu6IQS2Yfwenp3fB7Wo2DDTeTpQclRT plss7SrJj7QVdjrNEn0l/CCu23naD75UkTBAegu33M5NzJexcYZd08F1/MTmMJzbA1 J33BrqMTm+Bpzri0RU2ZIJ6qMVt5juO4jkkRZXPQ= From: Kieran Bingham Date: Mon, 23 Nov 2026 17:47:15 +0000 Subject: [PATCH 3/3] libcamera: pipeline_handler: Allow calling stop() on a disconnected camera MIME-Version: 1.0 Message-Id: <20261123-kbingham-atomic-disconnects-v1-3-0b251be0bb3e@ideasonboard.com> References: <20261123-kbingham-atomic-disconnects-v1-0-0b251be0bb3e@ideasonboard.com> In-Reply-To: <20261123-kbingham-atomic-disconnects-v1-0-0b251be0bb3e@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Stefan Klug X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795456039; l=2572; i=kieran.bingham@ideasonboard.com; s=20260207; h=from:subject:message-id; bh=+WDM+pC2IDRUXg9zqpiP+QjFvORk34UoONaf512/PCA=; b=Q8QCR/FN5pAETD+DHKJFoyQf/NDA2dYNmeUvM5qUR/1eiOAOTVsQEntOFTj1WycVWX6qGc8aS tCBPrzJSWK+B8L9InL4cXmZ6qdniPAjGF+XueYfl338rDwliBofSI7s X-Developer-Key: i=kieran.bingham@ideasonboard.com; a=ed25519; pk=FVXKN7YuwHc6UtbRUeTMAmranfsQomA+vnilfglWdaY= 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" From: Stefan Klug When a camera gets disconnected, the disconnected signal is emitted. If this happens while the camera is running, the application must call stop() on the camera to ensure all resources like queued requests are released properly. We can't call stop() from within libcamera as that would race with calls to queueRequest(). Modify the logic so that stop() is allowed in in disconnected state and adjust the documentation accordingly. Signed-off-by: Stefan Klug Signed-off-by: Kieran Bingham Reviewed-by: Kieran Bingham --- src/libcamera/camera.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index b6e2d3e51a46..d7b24961e40a 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -735,14 +735,6 @@ int Camera::Private::isAccessAllowed(State low, State high, void Camera::Private::disconnect() { - /* - * If the camera was running when the hardware was removed force the - * state to Configured state to allow applications to free resources - * and call release() before deleting the camera. - */ - if (state_.load(std::memory_order_acquire) == Private::CameraRunning) - state_.store(Private::CameraConfigured, std::memory_order_release); - disconnected_.store(true, std::memory_order_relaxed); } @@ -927,7 +919,9 @@ const std::string &Camera::id() const * physical device disconnection. The media device is passed as a parameter. * * As soon as this signal is emitted the camera instance will refuse all new - * application API calls by returning errors immediately. + * application API calls by returning errors immediately. The only exception is + * the stop() function which must be called on the camera if it was in running + * state before, to ensure all resources are released. */ Camera::Camera(std::unique_ptr d, const std::string &id, @@ -1443,7 +1437,6 @@ int Camera::start(const ControlList *controls) * running, it is a no-op. * * \return 0 on success or a negative error code otherwise - * \retval -ENODEV The camera has been disconnected from the system * \retval -EACCES The camera is not running so can't be stopped */ int Camera::stop() @@ -1457,7 +1450,7 @@ int Camera::stop() if (d->state() != Private::CameraRunning) return 0; - int ret = d->isAccessAllowed(Private::CameraRunning); + int ret = d->isAccessAllowed(Private::CameraRunning, true); if (ret < 0) return ret;