From e832a00bab6153e4bc3044dc413cee24e5181498 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 9 Sep 2019 17:18:03 +0300 Subject: 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 Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/libcamera/device_enumerator_udev.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libcamera/device_enumerator_udev.cpp') 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 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 if (ret) return ret; - orphans_.remove(devnum); + orphans_.erase(orphan); continue; } -- cgit v1.2.1