From 990ceeef3bfd9d56e2e6dd39cf5ac185b1a2de08 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 18 Jun 2022 23:37:12 +0000 Subject: [PATCH] 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 --- sys/src/cmd/nusb/usbd/hub.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/nusb/usbd/hub.c b/sys/src/cmd/nusb/usbd/hub.c index 1a484625d..e04a4aedc 100644 --- a/sys/src/cmd/nusb/usbd/hub.c +++ b/sys/src/cmd/nusb/usbd/hub.c @@ -355,6 +355,7 @@ portattach(Hub *h, int p, u32int sts) char *sp; int mp; int nr; + int i; d = h->dev; pp = &h->port[p]; @@ -421,9 +422,13 @@ portattach(Hub *h, int p, u32int sts) 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);