usb: core: Emit KOBJ_CHANGE when usb_reset_device() succeeds
PATCH 1/1 usb: core: Emit KOBJ_CHANGE when usb_reset_device() succeeds
When usb_reset_device() succeeds without re-enumerating the device, userspace receives no device-level uevent indicating that the reset has completed. For usbfs clients such as adb, usb_forced_unbind_intf() unbinds the interface before the port reset, and device_attach() leaves it unbound afterward because no kernel driver matches.
Since usbfs suppresses uevents on interface claim/release, userspace receives UNBIND(intf) before the reset and no event when the device is ready to be re-claimed, forcing it to fall back to polling /dev/bus/usb.
Emit KOBJ_CHANGE on &udev->dev.kobj in usb_reset_device() when the reset succeeds, after usb_unbind_and_rebind_marked_interfaces(udev), so userspace is notified (with DEVNAME) once the reset and all kernel interface rebinding are complete.
---
Tested across snd-usb-audio (no pre/post_reset), usbhid (with pre/post_reset), and usbfs (adb) using udevadm monitor:
Interface driver Uevent sequence on reset (ret == 0)
--------------------------------------------------------------------------
Kernel (no pre/post_reset) UNBIND(intf) -> BIND(intf) -> CHANGE(dev) Kernel (with pre/post_reset) CHANGE(dev) Userspace (usbfs, e.g. adb) UNBIND(intf) -> CHANGE(dev)
Discussion: https://lore.kernel.org/linux-usb/[email protected]/
drivers/usb/core/hub.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/core/hub.c +3 -1
@@ -6447,8 +6447,10 @@ int usb_reset_device(struct usb_device *udev) }/* If the reset failed, hub_wq will unbind drivers later */ -if (ret ==0 ) +if (ret ==0 ) {usb_unbind_and_rebind_marked_interfaces (udev); +kobject_uevent (&udev->dev.kobj,KOBJ_CHANGE ); + } }usb_autosuspend_device (udev);
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 10 lines
When
usb_reset_device()succeeds without re-enumerating the device, userspace receives no device-level uevent indicating that the reset has completed. For usbfs clients such as adb,usb_forced_unbind_intf()unbinds the interface before the port reset, anddevice_attach()leaves it unbound afterward because no kernel driver matches.Since usbfs suppresses uevents on interface claim/release, userspace receives UNBIND(intf) before the reset and no event when the device is ready to be re-claimed, forcing it to fall back to polling
/dev/bus/usb.
Quoted 7 lines
Emit
KOBJ_CHANGEon&udev->dev.kobjinusb_reset_device()when the reset succeeds, afterusb_unbind_and_rebind_marked_interfaces(udev), so userspace is notified (with DEVNAME) once the reset and all kernel interface rebinding are complete.Suggested-by Oliver Neukum <[email protected]>Signed-off-by Fabien Sanglard <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1