ref: ecba7822e316d6cb8370eec97862215402811e82
parent: 315f20b9f46671ca1fd323b22de0722c7c561f97
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Apr 4 23:05:06 EDT 2020
nusb/usbd: fix portreset error handling error handling in portreset() was wrong. we called closedev() on the device without changing the reference. just call portdetach() when the reset fails.
--- a/sys/src/cmd/nusb/usbd/hub.c
+++ b/sys/src/cmd/nusb/usbd/hub.c
@@ -543,7 +543,6 @@
d = h->dev;
pp = &h->port[p];
- nd = pp->dev;
dprint(2, "%s: %s: port %d: resetting\n", argv0, d->dir, p);
if(hubfeature(h, p, Fportreset, 1) < 0){
dprint(2, "%s: %s: port %d: reset: %r\n", argv0, d->dir, p);
@@ -557,7 +556,8 @@
dprint(2, "%s: %s: port %d: not enabled?\n", argv0, d->dir, p);
goto Fail;
}
- nd = pp->dev;
+ if((nd = pp->dev) == nil)
+ return;
opendevdata(nd, ORDWR);
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);
@@ -579,15 +579,10 @@
}
return;
Fail:
- pp->state = Pdisabled;
pp->sts = 0;
- if(pp->hub != nil)
- pp->hub = nil; /* hub closed by enumhub */
- if(!h->dev->isusb3)
+ portdetach(h, p);
+ if(!d->isusb3)
hubfeature(h, p, Fportenable, 0);
- if(nd != nil)
- devctl(nd, "detach");
- closedev(nd);
}
static int