From 3de05fcff6df96c20dbfec3a7d78afecd25b005e Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Tue, 22 Oct 2024 14:13:19 -0700 Subject: [PATCH] init: Move the stripping of "/devices" and "/devices/platform/" to a helper A future change will want the same stripping when looking for USB boot devices. Move the stripping down to the helper. This change is intended to be a no-op and just a reorganization. Bug: 316324155 Test: See boot devices still found Change-Id: I025d9d68fedf652055454cbd93e15f480b6056dd --- init/devices.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/init/devices.cpp b/init/devices.cpp index a2a1d3e1c..501657ac6 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -193,14 +193,6 @@ BlockDeviceInfo DeviceHandler::GetBlockDeviceInfo(const std::string& uevent_path BlockDeviceInfo info; if (FindPlatformDevice(uevent_path, &info.str)) { - // Skip /devices/platform or /devices/ if present - static constexpr std::string_view devices_platform_prefix = "/devices/platform/"; - static constexpr std::string_view devices_prefix = "/devices/"; - std::string_view str = info.str; - - if (ConsumePrefix(&str, devices_platform_prefix) || ConsumePrefix(&str, devices_prefix)) { - info.str = str; - } info.type = "platform"; } else if (FindPciDevicePrefix(uevent_path, &info.str)) { info.type = "pci"; @@ -265,7 +257,17 @@ bool DeviceHandler::FindSubsystemDevice(std::string path, std::string* device_pa subsystem_paths.find(subsystem_link_path) != subsystem_paths.end()) { // We need to remove the mount point that we added above before returning. directory.erase(0, sysfs_mount_point_.size()); - *device_path = directory; + + // Skip /devices/platform or /devices/ if present + static constexpr std::string_view devices_platform_prefix = "/devices/platform/"; + static constexpr std::string_view devices_prefix = "/devices/"; + std::string_view sv = directory; + + if (!ConsumePrefix(&sv, devices_platform_prefix)) { + ConsumePrefix(&sv, devices_prefix); + } + *device_path = sv; + return true; }