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
diff --git a/init/devices.cpp b/init/devices.cpp
index a2a1d3e..501657a 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -193,14 +193,6 @@
     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 @@
             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;
         }