summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-09-09 17:18:03 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-09-13 20:13:24 +0300
commite832a00bab6153e4bc3044dc413cee24e5181498 (patch)
tree57dc9120c42d2562711a98996110746c3b947a84
parent7516d410803309b42f45865eac6dec1a157e1976 (diff)
libcamera: device_enumerator_udev: Avoid double list lookup
DeviceEnumeratorUdev::populateMediaDevice() searches for orphan devices in an std::list, and if found removes them using std::list::remove(). This ends up looking up the entry twice. Replace the remove() call with erase() to fix it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
-rw-r--r--src/libcamera/device_enumerator_udev.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
index 210f5c1f..c4077091 100644
--- a/src/libcamera/device_enumerator_udev.cpp
+++ b/src/libcamera/device_enumerator_udev.cpp
@@ -182,7 +182,8 @@ int DeviceEnumeratorUdev::populateMediaDevice(const std::shared_ptr<MediaDevice>
entity->deviceMinor());
/* Take device from orphan list first, if it is in the list. */
- if (std::find(orphans_.begin(), orphans_.end(), devnum) != orphans_.end()) {
+ auto orphan = std::find(orphans_.begin(), orphans_.end(), devnum);
+ if (orphan != orphans_.end()) {
std::string deviceNode = lookupDeviceNode(devnum);
if (deviceNode.empty())
return -EINVAL;
@@ -191,7 +192,7 @@ int DeviceEnumeratorUdev::populateMediaDevice(const std::shared_ptr<MediaDevice>
if (ret)
return ret;
- orphans_.remove(devnum);
+ orphans_.erase(orphan);
continue;
}