Skip to content

Commit

Permalink
usb: hub: lack of clearing xHC resources
Browse files Browse the repository at this point in the history
The xHC resources allocated for USB devices are not released in correct
order after resuming in case when while suspend device was reconnected.

This issue has been detected during the fallowing scenario:
- connect hub HS to root port
- connect LS/FS device to hub port
- wait for enumeration to finish
- force host to suspend
- reconnect hub attached to root port
- wake host

For this scenario during enumeration of USB LS/FS device the Cadence xHC
reports completion error code for xHC commands because the xHC resources
used for devices has not been properly released.
XHCI specification doesn't mention that device can be reset in any order
so, we should not treat this issue as Cadence xHC controller bug.
Similar as during disconnecting in this case the device resources should
be cleared starting form the last usb device in tree toward the root hub.
To fix this issue usbcore driver should call hcd->driver->reset_device
for all USB devices connected to hub which was reconnected while
suspending.

Fixes: 3d82904 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
Cc: stable <stable@kernel.org>
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/PH7PR07MB953841E38C088678ACDCF6EEDDCC2@PH7PR07MB9538.namprd07.prod.outlook.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Pawel Laszczak authored and Greg Kroah-Hartman committed Mar 3, 2025
1 parent 552ca6b commit 2b66ef8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions drivers/usb/core/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -6065,6 +6065,36 @@ void usb_hub_cleanup(void)
usb_deregister(&hub_driver);
} /* usb_hub_cleanup() */

/**
* hub_hc_release_resources - clear resources used by host controller
* @udev: pointer to device being released
*
* Context: task context, might sleep
*
* Function releases the host controller resources in correct order before
* making any operation on resuming usb device. The host controller resources
* allocated for devices in tree should be released starting from the last
* usb device in tree toward the root hub. This function is used only during
* resuming device when usb device require reinitialization – that is, when
* flag udev->reset_resume is set.
*
* This call is synchronous, and may not be used in an interrupt context.
*/
static void hub_hc_release_resources(struct usb_device *udev)
{
struct usb_hub *hub = usb_hub_to_struct_hub(udev);
struct usb_hcd *hcd = bus_to_hcd(udev->bus);
int i;

/* Release up resources for all children before this device */
for (i = 0; i < udev->maxchild; i++)
if (hub->ports[i]->child)
hub_hc_release_resources(hub->ports[i]->child);

if (hcd->driver->reset_device)
hcd->driver->reset_device(hcd, udev);
}

/**
* usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
* @udev: device to reset (not in SUSPENDED or NOTATTACHED state)
Expand Down Expand Up @@ -6129,6 +6159,9 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
bos = udev->bos;
udev->bos = NULL;

if (udev->reset_resume)
hub_hc_release_resources(udev);

mutex_lock(hcd->address0_mutex);

for (i = 0; i < PORT_INIT_TRIES; ++i) {
Expand Down

0 comments on commit 2b66ef8

Please sign in to comment.