From patchwork Thu Sep 12 20:03:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1962 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 7BCDB60BCF for ; Thu, 12 Sep 2019 22:03:46 +0200 (CEST) Received: from pendragon.lan (bl10-204-24.dsl.telepac.pt [85.243.204.24]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B0BED33A; Thu, 12 Sep 2019 22:03:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1568318626; bh=8WZ0j3NkepX1Vnf4dCcBzOIHMU6JJmZJLIqiZDXgw0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CI68Kh1bloZuP1w1NxgREOUb8SXeHgiHG4Duze/hd+MS09NuJ+qnw40l83Q7H9+Jx Qw/Gqsl1Dhwe5GdLwPGxVnv5ZeMX5gBVv2EkOVzGZvSJ7LL4M77yAg+vICKOse02BI vEzpejq4IDJI47AP2XmeQZq71r4CAitsFnRSa4HE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 12 Sep 2019 23:03:29 +0300 Message-Id: <20190912200330.19004-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190912200330.19004-1-laurent.pinchart@ideasonboard.com> References: <20190912200330.19004-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] libcamera: device_enumerator_udev: Avoid double list lookup X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Sep 2019 20:03:46 -0000 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 --- src/libcamera/device_enumerator_udev.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index 210f5c1f2870..c40770911d3d 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; }