Re: [PATCH v2] usb: port: add delay after usb_hub_set_port_power()

From: Fabio Estevam

Date: Tue Feb 24 2026 - 07:20:39 EST


Hi Xu Yang,

On Tue, Feb 24, 2026 at 12:17 AM Xu Yang <xu.yang_2@xxxxxxx> wrote:
>
> 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: f061f43d7418 ("usb: hub: port: add sysfs entry to switch port power")
> Cc: stable@xxxxxxxxxx
> Signed-off-by: Xu Yang <xu.yang_2@xxxxxxx>

On an imx6x-sdb board, I still get the inconsistency below even after
applying your patch:

# echo 1 > /sys/bus/usb/devices/1-0\:1.0/usb1-port1/disable
[ 20.656414] usb 1-1: USB disconnect, device number 2

# echo 1 > /sys/bus/usb/devices/1-0\:1.0/usb1-port1/disable
[ 28.263516] usb 1-1: new high-speed USB device number 3 using ci_hdrc
[ 28.466813] usb 1-1: New USB device found, idVendor=0457,
idProduct=0151, bcdDevice= 1.00
[ 28.466949] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 28.467039] usb 1-1: Product: USB Mass Storage Device
[ 28.467086] usb 1-1: Manufacturer: USBest Technology
[ 28.467126] usb 1-1: SerialNumber: 000000000003FF
[ 28.501826] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 28.510452] usb-storage 1-1:1.0: Quirks match for vid 0457 pid 0151: 80
[ 28.517597] scsi host0: usb-storage 1-1:1.0
[ 28.524066] usb 1-1: USB disconnect, device number 3

# echo 1 > /sys/bus/usb/devices/1-0\:1.0/usb1-port1/disable
# [ 35.323593] usb 1-1: new high-speed USB device number 4 using ci_hdrc
[ 35.526916] usb 1-1: New USB device found, idVendor=0457,
idProduct=0151, bcdDevice= 1.00
[ 35.527054] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 35.527150] usb 1-1: Product: USB Mass Storage Device
[ 35.527198] usb 1-1: Manufacturer: USBest Technology
[ 35.527239] usb 1-1: SerialNumber: 000000000003FF
[ 35.562024] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 35.570430] usb-storage 1-1:1.0: Quirks match for vid 0457 pid 0151: 80
[ 35.577562] scsi host0: usb-storage 1-1:1.0
[ 36.645798] scsi 0:0:0:0: Direct-Access Ut163
USB2FlashStorage 0.00 PQ: 0 ANSI: 2

# [ 36.682705] sd 0:0:0:0: [sda] 248000 512-byte logical blocks:
(127 MB/121 MiB)
[ 36.691645] sd 0:0:0:0: [sda] Write Protect is off
[ 36.697915] sd 0:0:0:0: [sda] Asking for cache data failed
[ 36.697981] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 36.735520] sda: sda1
[ 36.739376] sd 0:0:0:0: [sda] Attached SCSI removable disk

# echo 1 > /sys/bus/usb/devices/1-0\:1.0/usb1-port1/disable
[ 39.423511] usb 1-1: USB disconnect, device number 4

Please try disabling the port several times in a row.