Skip to content

Commit 0a007f7

Browse files
groeckgregkh
authored andcommitted
usb: hub: Wait for connection to be reestablished after port reset
commit 22547c4cc4fe20698a6a85a55b8788859134b8e4 upstream. On a system with a defective USB device connected to an USB hub, an endless sequence of port connect events was observed. The sequence of events as observed is as follows: - Port reports connected event (port status=USB_PORT_STAT_CONNECTION). - Event handler debounces port and resets it by calling hub_port_reset(). - hub_port_reset() calls hub_port_wait_reset() to wait for the reset to complete. - The reset completes, but USB_PORT_STAT_CONNECTION is not immediately set in the port status register. - hub_port_wait_reset() returns -ENOTCONN. - Port initialization sequence is aborted. - A few milliseconds later, the port again reports a connected event, and the sequence repeats. This continues either forever or, randomly, stops if the connection is already re-established when the port status is read. It results in a high rate of udev events. This in turn destabilizes userspace since the above sequence holds the device mutex pretty much continuously and prevents userspace from actually reading the device status. To prevent the problem from happening, let's wait for the connection to be re-established after a port reset. If the device was actually disconnected, the code will still return an error, but it will do so only after the long reset timeout. Cc: Douglas Anderson <dianders@chromium.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f4522e3 commit 0a007f7

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/usb/core/hub.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,8 +2602,15 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
26022602
if (ret < 0)
26032603
return ret;
26042604

2605-
/* The port state is unknown until the reset completes. */
2606-
if (!(portstatus & USB_PORT_STAT_RESET))
2605+
/*
2606+
* The port state is unknown until the reset completes.
2607+
*
2608+
* On top of that, some chips may require additional time
2609+
* to re-establish a connection after the reset is complete,
2610+
* so also wait for the connection to be re-established.
2611+
*/
2612+
if (!(portstatus & USB_PORT_STAT_RESET) &&
2613+
(portstatus & USB_PORT_STAT_CONNECTION))
26072614
break;
26082615

26092616
/* switch to the long delay after two short delay failures */

0 commit comments

Comments
 (0)