From patchwork Wed Aug 7 13:49:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 20820 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 A2169BE173 for ; Wed, 7 Aug 2024 13:49:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4FDCB63394; Wed, 7 Aug 2024 15:49:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gz4VbUi6"; 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 EE41C6337F for ; Wed, 7 Aug 2024 15:49:54 +0200 (CEST) Received: from Monstersaurus.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 2214D96C; Wed, 7 Aug 2024 15:49:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723038542; bh=87qaTeZ4K0gRbq7cv67GpMRYcN+hw5vC4T128nalHfw=; h=From:To:Cc:Subject:Date:From; b=gz4VbUi6I2Nfu/cDwo/6clTEfZytEa+W4BIRyRFZFhaD9D2gX4Ivpj7SSMDDWz11s fzBMTFVsMDy/yRIM6wR7Ulia1BpVXpEo/I+nWYE6Fd3zgukdIyJ4d+RV1v6X0cnXGG ZiCueegF1vsi2NafWD/pAnzWOF9KAks/Pxz5X6Ig= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham , Stefan Klug Subject: [PATCH v2] libcamera: udev: Catch udev notification errors Date: Wed, 7 Aug 2024 14:49:50 +0100 Message-Id: <20240807134950.2458614-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.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 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 Reviewed-by: Stefan Klug Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- v2: - Report strerror based on errno from the udev_monitor_receive_device() call. src/libcamera/device_enumerator_udev.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index 01c70b6daa82..53eeb772d900 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -332,6 +332,14 @@ int DeviceEnumeratorUdev::addV4L2Device(dev_t devnum) void DeviceEnumeratorUdev::udevNotify() { struct udev_device *dev = udev_monitor_receive_device(monitor_); + if (!dev) { + int error = errno; + LOG(DeviceEnumerator, Warning) + << "Ignoring notfication received without a device: " + << strerror(error); + return; + } + std::string_view action(udev_device_get_action(dev)); std::string_view deviceNode(udev_device_get_devnode(dev));