diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-02-14 14:30:52 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-02-18 02:15:21 +0200 |
commit | 68daa9302f90833ce345cb33ffcf075f23cbfc9a (patch) | |
tree | c03db4fad3a976087220d12d9b0bd272f979836d /src | |
parent | 475f9b9b02d42318b8cdf17505fb2f5d546c04b5 (diff) |
libcamera: device_enumerator: Don't stop if one device fails
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/device_enumerator_sysfs.cpp | 16 | ||||
-rw-r--r-- | 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 ad26affb..197ca235 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<MediaDevice> 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<MediaDevice> &media) diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index b2c5fd22..87638c59 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: |