mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface
       [not found] <b7c2f7d1-40fd-4d83-8ced-5fc27e3be051@rowland.harvard.edu>
@ 2026-10-12 17:16 ` Fabien Sanglard
  2026-10-13  9:34   ` Oliver Neukum
  0 siblings, 1 reply; 4+ messages in thread
From: Fabien Sanglard @ 2026-10-12 17:16 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alan Stern; +Cc: linux-usb, linux-kernel, Fabien Sanglard

When an interface driver is forcibly unbound before a device reset,
usb_rebind_intf() attempts to re-attach a driver once the reset
completes in-place. Normal kernel drivers rebind and emit UNBIND
followed by BIND. However, usbfs only binds on explicit userspace
requests (e.g., USBDEVFS_CLAIMINTERFACE), so device_attach() returns 0
and no uevent is emitted.

As a result, userspace clients like adb only see UNBIND and must poll
/dev/bus/usb to detect when the interface is ready again. Emit a
KOBJ_CHANGE uevent when device_attach() finds no matching driver so
userspace is notified that the interface can be reclaimed.

Link: https://lore.kernel.org/linux-usb/CAA92w6k-LA4tVXyX1mFNOR3e+_mC43F_BXqhXeWqQyFx2D4_Mg@mail.gmail.com/
Signed-off-by: Fabien Sanglard <sanglardf@google.com>
---
 drivers/usb/core/driver.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 7f33fe5ba03b..25057423fda0 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1182,8 +1182,15 @@ static void usb_rebind_intf(struct usb_interface *intf)
 	if (!intf->dev.power.is_prepared) {
 		intf->needs_binding = 0;
 		rc = device_attach(&intf->dev);
-		if (rc < 0 && rc != -EPROBE_DEFER)
+		if (rc < 0 && rc != -EPROBE_DEFER) {
 			dev_warn(&intf->dev, "rebind failed: %d\n", rc);
+		} else if (rc == 0) {
+			/*
+			 * Emit a KOBJ_CHANGE uevent to notify userspace
+			 * that the interface could not be rebound.
+			 */
+			kobject_uevent(&intf->dev.kobj, KOBJ_CHANGE);
+		}
 	}
 }
 
-- 
2.55.0.1082.g2b9226bbc0-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface
  2026-10-12 17:16 ` [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface Fabien Sanglard
@ 2026-10-13  9:34   ` Oliver Neukum
  2026-10-13 16:48     ` Fabien Sanglard
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Neukum @ 2026-10-13  9:34 UTC (permalink / raw)
  To: Fabien Sanglard, Greg Kroah-Hartman, Alan Stern; +Cc: linux-usb, linux-kernel

On 12.10.26 19:16, Fabien Sanglard wrote:

> As a result, userspace clients like adb only see UNBIND and must poll
> /dev/bus/usb to detect when the interface is ready again. Emit a
> KOBJ_CHANGE uevent when device_attach() finds no matching driver so
> userspace is notified that the interface can be reclaimed.

Hi,

why do you want to limit this to that specific case?
Why not not always tell user space tat a device has
been reset?

	Regards
		Oliver


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface
  2026-10-13  9:34   ` Oliver Neukum
@ 2026-10-13 16:48     ` Fabien Sanglard
  2026-10-14  5:01       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Fabien Sanglard @ 2026-10-13 16:48 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Greg Kroah-Hartman, Alan Stern, linux-usb, linux-kernel

My original patch focuses on fixing the silent failure for usbfs
drivers (like ADB). Since other drivers survive a reset without issues
from a user space perspective, I wanted to avoid being disruptive to
unaffected systems.

That said, unifying the behavior upon reset would be elegant. My main
concern is whether some existing udev rules or netlink listeners in
user space might break if we generalize this behavior and start
emitting unexpected CHANGE events for interfaces that successfully
rebound (which already emit UNBIND -> BIND).

But it might be worth "trying". I am unsure what the kernel team
philosophy is in this regard. If you all agree, we could trigger the
KOBJ_CHANGE event unconditionally inside rebind_marked_interfaces()
instead of conditionally inside usb_rebind_intf().

Fab

On Tue, Oct 13, 2026 at 2:35 AM Oliver Neukum <oneukum@suse.com> wrote:
>
> On 12.10.26 19:16, Fabien Sanglard wrote:
>
> > As a result, userspace clients like adb only see UNBIND and must poll
> > /dev/bus/usb to detect when the interface is ready again. Emit a
> > KOBJ_CHANGE uevent when device_attach() finds no matching driver so
> > userspace is notified that the interface can be reclaimed.
>
> Hi,
>
> why do you want to limit this to that specific case?
> Why not not always tell user space tat a device has
> been reset?
>
>         Regards
>                 Oliver
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface
  2026-10-13 16:48     ` Fabien Sanglard
@ 2026-10-14  5:01       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2026-10-14  5:01 UTC (permalink / raw)
  To: Fabien Sanglard; +Cc: Oliver Neukum, Alan Stern, linux-usb, linux-kernel

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Tue, Oct 13, 2026 at 09:48:21AM -0700, Fabien Sanglard wrote:
> My original patch focuses on fixing the silent failure for usbfs
> drivers (like ADB). Since other drivers survive a reset without issues
> from a user space perspective, I wanted to avoid being disruptive to
> unaffected systems.
> 
> That said, unifying the behavior upon reset would be elegant. My main
> concern is whether some existing udev rules or netlink listeners in
> user space might break if we generalize this behavior and start
> emitting unexpected CHANGE events for interfaces that successfully
> rebound (which already emit UNBIND -> BIND).
> 
> But it might be worth "trying". I am unsure what the kernel team
> philosophy is in this regard. If you all agree, we could trigger the
> KOBJ_CHANGE event unconditionally inside rebind_marked_interfaces()
> instead of conditionally inside usb_rebind_intf().

Please try and test to verify.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-14  5:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <b7c2f7d1-40fd-4d83-8ced-5fc27e3be051@rowland.harvard.edu>
2026-10-12 17:16 ` [PATCH] usb: core: Emit KOBJ_CHANGE on unbound interface Fabien Sanglard
2026-10-13  9:34   ` Oliver Neukum
2026-10-13 16:48     ` Fabien Sanglard
2026-10-14  5:01       ` Greg Kroah-Hartman

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®