[Concept,09/33] usb: Drain finished scan threads after run_threads

Message ID 20260416023021.626949-10-sjg@u-boot.org
State New
Headers
Series Fix memory leaks and test pollution in sandbox tests |

Commit Message

Simon Glass April 16, 2026, 2:29 a.m. UTC
  From: Simon Glass <sjg@chromium.org>

run_threads() loops until uthread_grp_done() reports that every thread
in the group has finished. But uthread_schedule() only frees 'done'
threads it walks past on the way to the next runnable one - so when the
last thread completes, its uthread struct and 32 KB stack sit in the
list until something calls uthread_schedule() again. Nothing does, so
each usb_init() leaves one thread behind.

Call uthread_schedule() once more after the loop exits to drain the
tail.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/usb/host/usb-uclass.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index a7ac18a7a83..c2c6b79efde 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -375,6 +375,12 @@  static void run_threads(void)
 		return;
 	while (!uthread_grp_done(grp_id))
 		uthread_schedule();
+	/*
+	 * uthread_schedule() only frees 'done' threads it walks past
+	 * on the way to the next runnable one. Call it again so it
+	 * drains the tail of the list and releases the last thread.
+	 */
+	uthread_schedule();
 	nthr = 0;
 	grp_id = 0;
 #endif