From patchwork Mon Feb 17 11:03:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2839 Return-Path: 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 77CF660437 for ; Mon, 17 Feb 2020 12:03:46 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F1C83563 for ; Mon, 17 Feb 2020 12:03:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1581937426; bh=j4o9DoyxLt00ScSv8GxCPr2zC+Pp8zvw7ymCdv10pbE=; h=From:To:Subject:Date:From; b=qeQ1Ei0NRe0eyRRYmLtSoT52QtdBYdJeheHSVc3kotel3n5dkNs07ZcDa2XzrABP5 YFsZ5wWOGyxyV2qK9LKbRaiGdzSuJ5P01LHsJomTjw42MqredI5iAeGvGvAl9qcwdq fhmkawaz+dMz9+dTDk9MrP1CvjK+ALHTPf6HoL+s= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 17 Feb 2020 13:03:24 +0200 Message-Id: <20200217110324.7431-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: device_enumerator: Don't stop if one device fails 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: , X-List-Received-Date: Mon, 17 Feb 2020 11:03:46 -0000 If one device fails to enumerate, which isn't supposed to happen under normal conditions, both the sysfs and the udev enumerators stop enumeration of further devices. This potentially prevents working devices from being detected and handled. Fix it by skipping the faulty device. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- Changes since v1: - Add more warning messages to DeviceEnumeratorUdev - Use media->deviceNode() and print the driver name where appropriate --- src/libcamera/device_enumerator_sysfs.cpp | 16 +++++++-------- src/libcamera/device_enumerator_udev.cpp | 25 ++++++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp index ad26affb38a3..197ca235879b 100644 --- a/src/libcamera/device_enumerator_sysfs.cpp +++ b/src/libcamera/device_enumerator_sysfs.cpp @@ -33,7 +33,6 @@ int DeviceEnumeratorSysfs::enumerate() { struct dirent *ent; DIR *dir; - int ret = 0; static const char * const sysfs_dirs[] = { "/sys/subsystem/media/devices", @@ -74,14 +73,15 @@ int DeviceEnumeratorSysfs::enumerate() } std::shared_ptr media = createDevice(devnode); - if (!media) { - ret = -ENODEV; - break; - } + if (!media) + continue; if (populateMediaDevice(media) < 0) { - ret = -ENODEV; - break; + LOG(DeviceEnumerator, Warning) + << "Failed to populate media device " + << media->deviceNode() + << " (" << media->driver() << "), skipping"; + continue; } addDevice(media); @@ -89,7 +89,7 @@ int DeviceEnumeratorSysfs::enumerate() closedir(dir); - return ret; + return 0; } int DeviceEnumeratorSysfs::populateMediaDevice(const std::shared_ptr &media) diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index b2c5fd221dcd..87638c59761c 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -82,8 +82,15 @@ int DeviceEnumeratorUdev::addUdevDevice(struct udev_device *dev) return -ENODEV; int ret = populateMediaDevice(media); - if (ret == 0) - addDevice(media); + if (ret < 0) { + LOG(DeviceEnumerator, Warning) + << "Failed to populate media device " + << media->deviceNode() + << " (" << media->driver() << "), skipping"; + return ret; + } + + addDevice(media); return 0; } @@ -141,14 +148,18 @@ int DeviceEnumeratorUdev::enumerate() devnode = udev_device_get_devnode(dev); if (!devnode) { udev_device_unref(dev); - ret = -ENODEV; - goto done; + LOG(DeviceEnumerator, Warning) + << "Failed to get device node for '" + << syspath << "', skipping"; + continue; } - ret = addUdevDevice(dev); + if (addUdevDevice(dev) < 0) + LOG(DeviceEnumerator, Warning) + << "Failed to add device for '" + << syspath << "', skipping"; + udev_device_unref(dev); - if (ret < 0) - break; } done: