From a2173fca45983094cfde38359132cccec51b084c Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 13 May 2015 14:13:09 +0100 Subject: [PATCH] [usb] Do not call usb_hotplug() when registering a new hub MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The action of registering a new hub can itself happen in only two ways: either a new USB hub has been created (in which case we are already inside a call to usb_hotplug()), or a new root hub has been created. In the former case, we do not need to issue a further call to usb_hotplug(), since the hub's ports will all be marked as changed and so will be handled after the return from register_usb_hub() anyway. Calling usb_hotplug() within register_usb_hub() leads to a confusing order of events, such as: - root hub port 1 detects a change - root hub port 2 detects a change - usb_hotplug() is called - root hub port 1 finds a USB hub - usb_hotplug() is called - this inner call to usb_hotplug() handles root hub port 2 Fix by calling usb_hotplug() only from usb_step() and from register_usb_bus(). This avoids recursive calls to usb_hotplug() and ensures that devices are enumerated in the order of detection. Tested-by: Robin Smidsrød Signed-off-by: Michael Brown --- src/drivers/bus/usb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/bus/usb.c b/src/drivers/bus/usb.c index 085caf23..7574aaa1 100644 --- a/src/drivers/bus/usb.c +++ b/src/drivers/bus/usb.c @@ -1779,9 +1779,6 @@ int register_usb_hub ( struct usb_hub *hub ) { */ usb_poll ( bus ); - /* Attach any devices already present */ - usb_hotplug(); - return 0; hub->driver->close ( hub ); @@ -1915,6 +1912,9 @@ int register_usb_bus ( struct usb_bus *bus ) { if ( ( rc = register_usb_hub ( bus->hub ) ) != 0 ) goto err_register_hub; + /* Attach any devices already present */ + usb_hotplug(); + return 0; unregister_usb_hub ( bus->hub );