Skip to content

Commit

Permalink
[usb] Always clear recorded disconnections after performing hotplug a…
Browse files Browse the repository at this point in the history
…ctions

The recorded disconnections (in port->disconnected) will currently be
left uncleared if usb_attached() returns an error (e.g. because there
are no drivers for a particular USB device).  This is incorrect
behaviour: the disconnection has been handled and the record should be
cleared until the next physical disconnection is detected (via the CSC
bit).

The problem is masked for EHCI, UHCI, and USB hubs, since these will
report a changed port (via usb_port_changed()) only when the
underlying hardware reports a change.  xHCI will call
usb_port_changed() in response to any port status event, at which
point the stale value of port->disconnected will be erroneously acted
upon.  This can lead to an endless loop of repeatedly enumerating the
same device when a driverless device is attached to an xHCI root hub
port.

Fix by unconditionally clearing port->disconnected in usb_hotplugged().

Reported-by: Robin Smidsrød <robin@smidsrod.no>
Tested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed May 13, 2015
1 parent a2173fc commit 5ecd16a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/drivers/bus/usb.c
Expand Up @@ -1591,23 +1591,23 @@ static int usb_hotplugged ( struct usb_port *port ) {
if ( ( rc = hub->driver->speed ( hub, port ) ) != 0 ) {
DBGC ( hub, "USB hub %s port %d could not get speed: %s\n",
hub->name, port->address, strerror ( rc ) );
return rc;
goto err_speed;
}

/* Detach device, if applicable */
if ( port->attached && ( port->disconnected || ! port->speed ) )
usb_detached ( port );

/* Attach device, if applicable */
if ( port->speed && ! port->attached ) {
if ( ( rc = usb_attached ( port ) ) != 0 )
return rc;
}
if ( port->speed && ( ! port->attached ) &&
( ( rc = usb_attached ( port ) ) != 0 ) )
goto err_attached;

err_attached:
err_speed:
/* Clear any recorded disconnections */
port->disconnected = 0;

return 0;
return rc;
}

/******************************************************************************
Expand Down

0 comments on commit 5ecd16a

Please sign in to comment.