mirror-linux/drivers/usb/core
Xu Yang b84cc80610 usb: port: add delay after usb_hub_set_port_power()
When a port is disabled, an attached device will be disconnected.  This
causes a port-status-change event, which will race with hub autosuspend
(if the disabled port was the only connected port on its hub), causing
an immediate resume and a second autosuspend.  Both of these can be
avoided by adding a short delay after the call to
usb_hub_set_port_power().

Below log shows what is happening:

$ echo 1 > usb1-port1/disable
[   37.958239] usb 1-1: USB disconnect, device number 2
[   37.964101] usb 1-1: unregistering device
[   37.970070] hub 1-0:1.0: hub_suspend
[   37.971305] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0002
[   37.974412] usb usb1: bus auto-suspend, wakeup 1
[   37.988175] usb usb1: suspend raced with wakeup event         <---
[   37.993947] usb usb1: usb auto-resume
[   37.998401] hub 1-0:1.0: hub_resume
[   38.105688] usb usb1-port1: status 0000, change 0000, 12 Mb/s
[   38.112399] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0000
[   38.118645] hub 1-0:1.0: hub_suspend
[   38.122963] usb usb1: bus auto-suspend, wakeup 1
[   38.200368] usb usb1: usb wakeup-resume
[   38.204982] usb usb1: usb auto-resume
[   38.209376] hub 1-0:1.0: hub_resume
[   38.213676] usb usb1-port1: status 0101 change 0001
[   38.321552] hub 1-0:1.0: state 7 ports 1 chg 0002 evt 0000
[   38.327978] usb usb1-port1: status 0101, change 0000, 12 Mb/s
[   38.457429] usb 1-1: new high-speed USB device number 3 using ci_hdrc

Then, port change bit will be fixed to the final state and
usb_clear_port_feature() can correctly clear it after this period. This
will also avoid usb runtime suspend routine to run because
usb_autopm_put_interface() not run yet.

Fixes: f061f43d74 ("usb: hub: port: add sysfs entry to switch port power")
Cc: stable@kernel.org
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Link: https://patch.msgid.link/20260316095042.1559882-1-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-03-18 16:03:58 +01:00
..
Kconfig
Makefile usb: core: Add tracepoints for device allocation and state changes 2025-10-22 10:58:30 +02:00
buffer.c
config.c usb: core: new quirk to handle devices with zero configurations 2026-03-11 16:17:19 +01:00
devices.c
devio.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
driver.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
endpoint.c usb: endpoint: drop custom sysfs attribute structure 2026-03-11 15:48:20 +01:00
file.c
generic.c USB: lower "Device is not authorized for usage" message to info 2025-08-13 16:55:27 +02:00
hcd-pci.c usb: core: modify comments xhci_hc_driver has HCD_MEMORY just like ehci ohci 2025-06-19 12:31:16 +02:00
hcd.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
hub.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
hub.h usb: hub: Fix flushing of delayed work used for post resume purposes 2025-06-30 15:36:00 +02:00
ledtrig-usbport.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
message.c USB: core: Use krealloc() in usb_cache_string() 2026-03-18 16:03:52 +01:00
notify.c
of.c
offload.c usb: offload: add apis for offload usage tracking 2025-09-12 14:08:02 +02:00
otg_productlist.h
phy.c usb: core: don't power off roothub PHYs if phy_set_mode() fails 2026-03-11 16:16:41 +01:00
phy.h
port.c usb: port: add delay after usb_hub_set_port_power() 2026-03-18 16:03:58 +01:00
quirks.c USB: ezcap401 needs USB_QUIRK_NO_BOS to function on 10gbs usb speed 2026-03-13 18:19:07 +01:00
sysfs.c sysfs: treewide: switch back to attribute_group::bin_attrs 2025-06-17 10:44:15 +02:00
trace.c usb: core: Add tracepoints for device allocation and state changes 2025-10-22 10:58:30 +02:00
trace.h usb: core: Add tracepoints for device allocation and state changes 2025-10-22 10:58:30 +02:00
urb.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
usb-acpi.c usb: acpi: fix device link removal 2025-06-19 12:36:19 +02:00
usb.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
usb.h