mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: core: Emit KOBJ_CHANGE when usb_reset_device() succeeds
@ 2026-11-03 23:51 Fabien Sanglard
  0 siblings, 0 replies; only message in thread
From: Fabien Sanglard @ 2026-11-03 23:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alan Stern
  Cc: Oliver Neukum, linux-usb, linux-kernel, Fabien Sanglard

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.

Suggested-by: Oliver Neukum <oneukum@suse.com>
Signed-off-by: Fabien Sanglard <sanglardf@google.com>
---
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/20261012171609.88273-1-sanglardf@google.com/

 drivers/usb/core/hub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 199d3f535..9b3835ced 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -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
-- 
2.56.0.385.gac671c819a-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-03 23:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 23:51 [PATCH] usb: core: Emit KOBJ_CHANGE when usb_reset_device() succeeds Fabien Sanglard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®