From patchwork Mon Nov 30 23:08:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Menzel X-Patchwork-Id: 29116 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 B9E44C3304 for ; Tue, 1 Dec 2026 01:39:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A1A886AA86; Tue, 1 Dec 2026 02:39:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=molgen.mpg.de header.i=@molgen.mpg.de header.b="la38N5Xz"; dkim-atps=neutral Received: from mx3.molgen.mpg.de (mx3.molgen.mpg.de [141.14.17.11]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C20BB6AA77 for ; Tue, 1 Dec 2026 00:09:37 +0100 (CET) Received: from localhost (hotelcalifornia.molgen.mpg.de [141.14.16.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx.molgen.mpg.de (Postfix) with ESMTPS id 1C8514C442F948; Tue, 01 Dec 2026 00:09:28 +0100 (CET) From: Paul Menzel To: libcamera-devel@lists.libcamera.org Cc: Paul Menzel , Laurent Pinchart , Kieran Bingham , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= , Milan Zamazal , Hans de Goede Subject: [PATCH 2/2] pipeline: simple: Enable hot-unplug of the media devices Date: Tue, 1 Dec 2026 00:08:28 +0100 Message-ID: <20261130230839.95850-4-pmenzel@molgen.mpg.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261130230839.95850-2-pmenzel@molgen.mpg.de> References: <20261130230839.95850-2-pmenzel@molgen.mpg.de> MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=molgen.mpg.de; s=20260906; t=1796080168; h=from:from:subject:date:message-id:mime-version:content-type:content-transfer-encoding; bh=TxZ/iWnj6M2HKFJ/N0OIMHCjccyPNUGHBiwPKZJWTAs=; b=la38N5XzCbQ6mxjmY4aT1aL2Dp87eF6xyGe9Gb+4z+MLJgA/YTOQH5IqkpKQy72wgSGX8JEZveW6 h+EoGueUFxEir52IrB83LBHn+cDAoLDo8CoBVso59rODDc3fKOfZfJYy529AS1vxfWhp9vRHhfWRb7 1ARrKd76IfAljwel8S4kuZhXczU0HlV5jHk0EIbOz9/seXnFpIt4dT53FlNUKnSIHitHgv5kVzR7cu HgSWVDNKl5ScNyRzuW+D471UkrDfIVwPiAS2EVIWRmgns0xwCSGlJdO/mQuHaUbd5eTY8HeYwfHhU/ GF7Bh7sSbIthJBRNlyLwK2DNS6ygmgwg== X-Mailman-Approved-At: Tue, 01 Dec 2026 02:39:29 +0100 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 The simple pipeline handler does not call hotplugMediaDevice(), so its cameras stay registered when their media device goes away, for instance when the driver is unbound. If the media device comes back, the new instance yields a camera with the same ID. Before commit 50858dc3 ("libcamera: camera_manager: Non-fatal duplicate id detection") this aborted the process, as seen in WirePlumber on a Dell XPS 9315 (Intel IPU6) when the media device and its V4L2 nodes were removed and added again with synthetic udev events: FATAL Camera camera_manager.cpp:213 Trying to register a camera with a duplicated ID '\_SB_.PC00.LNK1' Now the new camera is dropped instead, and the stale one stays. With a real driver unbind on the same laptop (intel_ipu6_isys) and libcamera 0.7.2, the enumerator removes /dev/media0, DEBUG DeviceEnumerator device_enumerator.cpp:331 Media device for node /dev/media0 removed. but PipeWire keeps listing the camera, and the stale camera keeps its V4L2 device nodes open. After binding the driver again, only four of the six V4L2 subdevices came back (CSI2 0-3, numbered 0, 1, 3 and 6), the IVSC CSI and sensor subdevices were missing, and no camera was added. When WirePlumber closed the stale handles at shutdown, the kernel crashed in v4l2_release() (a separate kernel bug, the IPU6 driver frees its video devices on unbind while they are open [1]). Enable hot-unplug notifications for the media device, and for the converter if one is used, once a camera has been registered, like the UVC pipeline handler does. With this change, on the same laptop and in the same test (2 of 2 runs), the camera is removed when intel_ipu6_isys is unbound, and after binding it again all six subdevices are back and the camera is added again in the same WirePlumber process: DEBUG DeviceEnumerator device_enumerator.cpp:333 Media device for node /dev/media0 removed. INFO Camera camera_manager.cpp:223 Adding camera '\_SB_.PC00.LNK1' for pipeline handler simple [1]: https://lore.kernel.org/all/abcc474a-bd58-45da-8551-d7925ca18d52@molgen.mpg.de/ Signed-off-by: Paul Menzel --- Notes: This patch was written with the help of an LLM (Claude Code, claude-opus-5.5). It was built and tested on the Dell XPS 9315 as described above (on top of libcamera 0.7.2, where the touched files are identical), and compile-tested on master with the unit tests. The test only checked that the camera is listed again, not that it streams. src/libcamera/pipeline/simple/simple.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 2f7f4c89..e658f85a 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -2082,7 +2082,20 @@ bool SimplePipelineHandler::matchDevice(std::shared_ptr media, registered = true; } - return registered; + if (!registered) + return false; + + /* + * Enable hot-unplug notifications. Platform media devices go away + * when their driver is unbound, and the cameras have to be + * unregistered then, or they would clash with the cameras created + * when the driver is bound again. + */ + hotplugMediaDevice(media); + if (converter_) + hotplugMediaDevice(converter_); + + return true; } bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)