[PATCH 10/13] usb: don't keep a dangling root device on enumeration failure

Sascha Hauer s.hauer at pengutronix.de
Mon Aug 31 06:20:17 PDT 2026


When usb_new_device() fails for the root hub, usb_host_detect() frees it
but leaves host->root_dev pointing at the freed memory. The next "usb"
run finds the pointer non-NULL, skips the re-initialisation and hands the
freed device to device_detect().

Clear the pointer so the next scan starts over.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Assisted-by: Claude:claude-opus-5
---
 drivers/usb/core/usb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index ad0d0965b1..55c57e6334 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -704,6 +704,7 @@ int usb_host_detect(struct usb_host *host)
 		ret = usb_new_device(host->root_dev);
 		if (ret) {
 			usb_free_device(host->root_dev);
+			host->root_dev = NULL;
 			return ret;
 		}
 	}

-- 
2.47.3




More information about the barebox mailing list