From patchwork Mon Aug 5 22:31:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 20807 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 74136BE173 for ; Mon, 5 Aug 2024 22:31:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5AD5E63393; Tue, 6 Aug 2024 00:31:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lI0Uqn0g"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 327506192D for ; Tue, 6 Aug 2024 00:31:53 +0200 (CEST) Received: from charm.tail69b4.ts.net (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4EBBB39F; Tue, 6 Aug 2024 00:31:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1722897061; bh=Tkz1eDJMW6bBY9m0s+nSpVlstzfpRJK8osxMpEJW2Bc=; h=From:To:Cc:Subject:Date:From; b=lI0Uqn0gH55W1WZjVRj34Ext4AqfwbeQZhFxLrBPGpVGp0ny8+m/JY28JbgJsLUxi I877UVAm9rrsULdbPdr1J2QQxoCS+2yewhtYEPVbPy2AfNv0oJuONRg3gTNkCP1Q+A q6o1WoXdOTBulQveun8J4POCDXfL6ff1wPQ2LDUI= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham Subject: [PATCH] libcamera: udev: Catch udev notification errors Date: Mon, 5 Aug 2024 23:31:48 +0100 Message-ID: <20240805223148.30605-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.45.2 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 udev_monitor_receive_device() can return NULL on an error as detailed in the man pages for the function. The udevNotify() handler in the DeviceEnumeratorUdev directly uses the return value of udev_monitor_receive_device() in successive calls to process the event without having first checked the udev_device. Ensure we identify, and handle events where the udev_device can not be returned successfully. Bug: https://bugs.libcamera.org/show_bug.cgi?id=230 Signed-off-by: Kieran Bingham Signed-off-by: Stefan Klug --- This is a proposed fix for the reported CI failure caught by Systemd runners. It's not clear if this failure was an injected failure, startup race or otherwise - but given the documentation of this function states it can return null ... it seems valid to null check before passing into other APIs especially when a trace is reported directly at this point. I don't presently have a way to replicate or reproduce the error either, but this patch itself has passed our ci tests (which isn't too unexpected as the change is quite minimal otherwise). src/libcamera/device_enumerator_udev.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index 01c70b6daa82..c6c78651baa0 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -332,6 +332,12 @@ int DeviceEnumeratorUdev::addV4L2Device(dev_t devnum) void DeviceEnumeratorUdev::udevNotify() { struct udev_device *dev = udev_monitor_receive_device(monitor_); + if (!dev) { + LOG(DeviceEnumerator, Warning) + << "Ignoring notfication received without a device"; + return; + } + std::string_view action(udev_device_get_action(dev)); std::string_view deviceNode(udev_device_get_devnode(dev));