From 150687b87d61cf3f07083a77b0fee38f21a84c68 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 12 May 2020 18:13:14 -0700 Subject: [PATCH] init: failed to set sys.usb.controller With GKI we find in certain situations the timing of the drivers loading is delayed as compared to a monolithic kernel. This introduces a race where during second stage init, the attributes inside /sys/class/udc/ might not be set by the time SetUsbController() is called. To address this, we also call SetUsbController() until the property sys.usb.controller is set at the bottom of the event loop. Signed-off-by: Mark Salyzyn Bug: 151950334 Test: make sure user space fastbootd comes up reliably for a GKI kernel Change-Id: Iececd8ffa3e6641554d215d622d8dab72d85d34d --- init/init.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/init/init.cpp b/init/init.cpp index 3f8f6281c..631db8e7f 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -537,7 +537,9 @@ static Result queue_property_triggers_action(const BuiltinArguments& args) // Set the UDC controller for the ConfigFS USB Gadgets. // Read the UDC controller in use from "/sys/class/udc". // In case of multiple UDC controllers select the first one. -static void set_usb_controller() { +static void SetUsbController() { + static auto controller_set = false; + if (controller_set) return; std::unique_ptrdir(opendir("/sys/class/udc"), closedir); if (!dir) return; @@ -546,6 +548,7 @@ static void set_usb_controller() { if (dp->d_name[0] == '.') continue; SetProperty("sys.usb.controller", dp->d_name); + controller_set = true; break; } } @@ -800,7 +803,7 @@ int SecondStageMain(int argc, char** argv) { fs_mgr_vendor_overlay_mount_all(); export_oem_lock_status(); MountHandler mount_handler(&epoll); - set_usb_controller(); + SetUsbController(); const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap(); Action::set_function_map(&function_map); @@ -910,6 +913,7 @@ int SecondStageMain(int argc, char** argv) { } if (!IsShuttingDown()) { HandleControlMessages(); + SetUsbController(); } }