From patchwork Fri Feb 14 12:37:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2833 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 B3840607E9 for ; Fri, 14 Feb 2020 13:37:35 +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 369D2504 for ; Fri, 14 Feb 2020 13:37:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1581683855; bh=w45EtP4DPwzSPcx/KavL5KKeGPmnHtt572Z4NRB6KsI=; h=From:To:Subject:Date:From; b=O7IL355D7PhGVWO3cdhvBhnQg2IY9/iBjiZCr1KcuiwvDgyZIyUvBJxN43J+GRTPD 7JqEik9BeThh2VQJkZZtz2VRV9ef6phrYoy9U2D2QXN8sZNDexuxe59bG4sBbqPdTv 4AWvMjQTdKIKWydnjoSWWYZks3uH0gpPehaC8XGc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 14 Feb 2020 14:37:15 +0200 Message-Id: <20200214123715.13026-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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: Fri, 14 Feb 2020 12:37:35 -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 Tested-by: Kieran Bingham Reviewed-by: Kieran Bingham --- src/libcamera/device_enumerator_sysfs.cpp | 15 +++++++-------- src/libcamera/device_enumerator_udev.cpp | 8 +++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp index ad26affb38a3..bde736226f95 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,14 @@ 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 /dev/media" + << idx << ", skipping"; + continue; } addDevice(media); @@ -89,7 +88,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..3837aaf97e6a 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -145,10 +145,12 @@ int DeviceEnumeratorUdev::enumerate() goto done; } - 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: