Skip to content

Commit 657003c

Browse files
matnymangregkh
authored andcommitted
usb: Flush altsetting 0 endpoints before reinitializating them after reset.
commit 89bb3dc upstream. 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 921b3c8 commit 657003c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/usb/core/hub.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6135,6 +6135,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
61356135
struct usb_hub *parent_hub;
61366136
struct usb_hcd *hcd = bus_to_hcd(udev->bus);
61376137
struct usb_device_descriptor descriptor;
6138+
struct usb_interface *intf;
61386139
struct usb_host_bos *bos;
61396140
int i, j, ret = 0;
61406141
int port1 = udev->portnum;
@@ -6192,6 +6193,18 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
61926193
if (!udev->actconfig)
61936194
goto done;
61946195

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

6241+
intf = config->interface[i];
62296242
desc = &intf->cur_altsetting->desc;
62306243
if (desc->bAlternateSetting == 0) {
6231-
usb_disable_interface(udev, intf, true);
62326244
usb_enable_interface(udev, intf, true);
62336245
ret = 0;
62346246
} else {

0 commit comments

Comments
 (0)