Skip to content

Commit 89bb3dc

Browse files
matnymangregkh
authored andcommitted
usb: Flush altsetting 0 endpoints before reinitializating them after reset.
usb core avoids sending a Set-Interface altsetting 0 request after device reset, and instead relies on calling usb_disable_interface() and usb_enable_interface() to flush and reset host-side of those endpoints. xHCI hosts allocate and set up endpoint ring buffers and host_ep->hcpriv during usb_hcd_alloc_bandwidth() callback, which in this case is called before flushing the endpoint in usb_disable_interface(). Call usb_disable_interface() before usb_hcd_alloc_bandwidth() to ensure URBs are flushed before new ring buffers for the endpoints are allocated. Otherwise host driver will attempt to find and remove old stale URBs from a freshly allocated new ringbuffer. Cc: stable <stable@kernel.org> Fixes: 4fe0387 ("USB: don't send Set-Interface after reset") Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://lore.kernel.org/r/20250514132520.225345-1-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e33ebb1 commit 89bb3dc

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

drivers/usb/core/hub.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6137,6 +6137,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
61376137
struct usb_hub *parent_hub;
61386138
struct usb_hcd *hcd = bus_to_hcd(udev->bus);
61396139
struct usb_device_descriptor descriptor;
6140+
struct usb_interface *intf;
61406141
struct usb_host_bos *bos;
61416142
int i, j, ret = 0;
61426143
int port1 = udev->portnum;
@@ -6194,6 +6195,18 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
61946195
if (!udev->actconfig)
61956196
goto done;
61966197

6198+
/*
6199+
* Some devices can't handle setting default altsetting 0 with a
6200+
* Set-Interface request. Disable host-side endpoints of those
6201+
* interfaces here. Enable and reset them back after host has set
6202+
* its internal endpoint structures during usb_hcd_alloc_bandwith()
6203+
*/
6204+
for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
6205+
intf = udev->actconfig->interface[i];
6206+
if (intf->cur_altsetting->desc.bAlternateSetting == 0)
6207+
usb_disable_interface(udev, intf, true);
6208+
}
6209+
61976210
mutex_lock(hcd->bandwidth_mutex);
61986211
ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL);
61996212
if (ret < 0) {
@@ -6225,12 +6238,11 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
62256238
*/
62266239
for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
62276240
struct usb_host_config *config = udev->actconfig;
6228-
struct usb_interface *intf = config->interface[i];
62296241
struct usb_interface_descriptor *desc;
62306242

6243+
intf = config->interface[i];
62316244
desc = &intf->cur_altsetting->desc;
62326245
if (desc->bAlternateSetting == 0) {
6233-
usb_disable_interface(udev, intf, true);
62346246
usb_enable_interface(udev, intf, true);
62356247
ret = 0;
62366248
} else {

0 commit comments

Comments
 (0)