nusbd: properly handle port detach on hub disconnect

This commit is contained in:
cinap_lenrek 2012-09-05 00:06:20 +02:00
parent 0c52215ae3
commit 93063b3db0
2 changed files with 7 additions and 3 deletions

View file

@ -481,6 +481,8 @@ portdetach(Hub *h, int p)
putdevnb(pp->devmaskp, pp->devnb);
pp->devmaskp = nil;
if(pp->dev != nil){
detachdev(pp);
devctl(pp->dev, "detach");
closedev(pp->dev);
pp->dev = nil;
@ -562,8 +564,10 @@ portreset(Hub *h, int p)
if(usbcmd(nd, Rh2d|Rstd|Rdev, Rsetconf, 1, 0, nil, 0) < 0)
goto Fail;
}
if(nd->dfd >= 0)
if(nd->dfd >= 0){
close(nd->dfd);
nd->dfd = -1;
}
return;
Fail:
pp->state = Pdisabled;
@ -623,8 +627,6 @@ enumhub(Hub *h, int p)
if(attachdev(pp) < 0)
portdetach(h, p);
}else if(portgone(pp, sts)){
if(pp->dev)
detachdev(pp);
portdetach(h, p);
}else if(portresetwanted(h, p))
portreset(h, p);

View file

@ -338,6 +338,8 @@ attachdev(Port *p)
void
detachdev(Port *p)
{
if(p->dev->usb->class == Clhub)
return;
pushevent(formatdev(p->dev, 1));
}