git: plan9front

Download patch

ref: 33a0d0599932e4d7190b06a4fc94c0b9ef031d9a
parent: 654fdc9f9ada37b7b1d58179e3d44133c4b38547
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jan 15 12:35:38 EST 2025

nusb/usbd: maintain hublist order with rootports first

This ensures that on a portstatus() error or port
detach, we always restart enumeration from the
rootports down and avoid talking to intermediate
hubs that are in the tree that got disconnected.

--- a/sys/src/cmd/nusb/usbd/hub.c
+++ b/sys/src/cmd/nusb/usbd/hub.c
@@ -187,7 +187,7 @@
 Hub*
 newhub(char *fn, Dev *d)
 {
-	Hub *h;
+	Hub *h, **hl;
 	int i;
 	Usbdev *ud;
 
@@ -232,8 +232,11 @@
 		for(i = 1; i <= h->nport; i++)
 			portfeature(h, i, Fportindicator, 1);
 	}
-	h->next = hubs;
-	hubs = h;
+	/* link to tail, so we always enumarte from the root */
+	h->next = nil;
+	for(hl = &hubs; *hl != nil; hl = &(*hl)->next)
+		;
+	*hl = h;
 	nhubs++;
 	dprint(2, "%s: %s: hub %#p allocated:", argv0, fn, h);
 	dprint(2, " ports %d pwrms %d max curr %d pwrm %d cmp %d leds %d\n",
--