shithub: riscv

Download patch

ref: 990ceeef3bfd9d56e2e6dd39cf5ac185b1a2de08
parent: 2b1ecbe87da757ddb12e38239773a05f816d03ae
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jun 18 19:37:12 EDT 2022

nusb/usbd: retry opendevtata() a few times on attach (work around mnt-reform trackball)

this is a known and already fixed issue with version the following version
of the mnt-reform trackball firmware:

https://source.mnt.re/reform/reform/-/commit/55ca5bf848b57cdf6e7243fc1018411f6c8ab9b5

--- a/sys/src/cmd/nusb/usbd/hub.c
+++ b/sys/src/cmd/nusb/usbd/hub.c
@@ -355,6 +355,7 @@
 	char *sp;
 	int mp;
 	int nr;
+	int i;
 
 	d = h->dev;
 	pp = &h->port[p];
@@ -421,9 +422,13 @@
 	nd->isusb3 = h->dev->isusb3;
 	if(usbdebug > 2)
 		devctl(nd, "debug 1");
-	if(opendevdata(nd, ORDWR) < 0){
+	for(i=0;; i++){
+		if(opendevdata(nd, ORDWR) >= 0)
+			break;
 		fprint(2, "%s: %s: opendevdata: %r\n", argv0, nd->dir);
-		goto Fail;
+		if(i >= 4)
+			goto Fail;
+		sleep(500);
 	}
 	if(usbcmd(nd, Rh2d|Rstd|Rdev, Rsetaddress, nd->id, 0, nil, 0) < 0){
 		dprint(2, "%s: %s: port %d: setaddress: %r\n", argv0, d->dir, p);