shithub: riscv

Download patch

ref: 6056f3eb21c2ef885cba92e5cfc462cb22511fde
parent: 528fa0acfa3532dee4a50fca1ae49d147403edfc
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Jun 8 18:06:16 EDT 2023

nusb/usbd: Fix wrong hname collision handling

Just counting collisions does not result in a
unique id as devices can vanish and re-appear
out of order.

Just use the maximum collision number + 1.

--- a/sys/src/cmd/nusb/usbd/usbd.c
+++ b/sys/src/cmd/nusb/usbd/usbd.c
@@ -452,7 +452,7 @@
 	char buf[64];
 	Usbdev *ud;
 	Hub *h;
-	int col;
+	int col, nr;
 	int i, n;
 
 	ud = dev->usb;
@@ -469,8 +469,11 @@
 		if(ud->class == Clhub){
 			if(h->dev->hname == nil)
 				continue;
-			if(strncmp(h->dev->hname, buf, n) == 0)
-				col++;
+			if(strncmp(h->dev->hname, buf, n) == 0){
+				nr = atoi(h->dev->hname+n)+1;
+				if(nr > col)
+					col = nr;
+			}
 			continue;
 		}
 		for(i = 1; i <= h->nport; i++){
@@ -478,8 +481,11 @@
 				continue;
 			if(h->port[i].dev->hname == nil || h->port[i].dev == dev)
 				continue;
-			if(strncmp(h->port[i].dev->hname, buf, n) == 0)
-				col++;
+			if(strncmp(h->port[i].dev->hname, buf, n) == 0){
+				nr = atoi(h->port[i].dev->hname+n)+1;
+				if(nr > col)
+					col = nr;
+			}
 		}
 	}