mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] USB: core: document purpose of interface parent reference
@ 2026-10-15  7:48 Johan Hovold
  2026-10-15  8:08 ` Danilo Krummrich
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2026-10-15  7:48 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Alan Stern, Danilo Krummrich, linux-usb, linux-kernel, Johan Hovold

USB interfaces hold a reference to their parent USB device to make sure
they do not outlive the parent.

Add a comment explaining that this reference is specifically needed for
asynchronous device resets and the device type need_parent_lock feature
(to allow driver core to lock the parent when only holding a reference
to the interface).

See commits:

  524134d42231 ("USB: don't cancel queued resets when unbinding drivers")
  af61396a992b ("driver core: fix parent lock use-after-free on USB disconnect")

for further details.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/core/message.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 276768f47558..a738d03c23ea 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -2209,6 +2209,11 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
 		pm_runtime_no_callbacks(&intf->dev);
 		dev_set_name(&intf->dev, "%d-%s:%d.%d", dev->bus->busnum,
 				dev->devpath, configuration, ifnum);
+		/*
+		 * Make sure the interface does not outlive its parent (e.g.
+		 * as needed for usb_queue_reset_device() and
+		 * usb_if_device_type->need_parent_lock).
+		 */
 		usb_get_dev(dev);
 	}
 	kfree(new_interfaces);
-- 
2.55.0


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

* Re: [PATCH] USB: core: document purpose of interface parent reference
  2026-10-15  7:48 [PATCH] USB: core: document purpose of interface parent reference Johan Hovold
@ 2026-10-15  8:08 ` Danilo Krummrich
  2026-10-15  8:28   ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Danilo Krummrich @ 2026-10-15  8:08 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Greg Kroah-Hartman, Alan Stern, linux-usb, linux-kernel

On Thu Oct 15, 2026 at 9:48 AM CEST, Johan Hovold wrote:
> USB interfaces hold a reference to their parent USB device to make sure
> they do not outlive the parent.
>
> Add a comment explaining that this reference is specifically needed for
> asynchronous device resets and the device type need_parent_lock feature
> (to allow driver core to lock the parent when only holding a reference
> to the interface).
>
> See commits:
>
>   524134d42231 ("USB: don't cancel queued resets when unbinding drivers")
>   af61396a992b ("driver core: fix parent lock use-after-free on USB disconnect")
>
> for further details.
>
> Signed-off-by: Johan Hovold <johan@kernel.org>

NIT: Maybe add that the reference count must be held until release().

In any case,

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

> ---
>  drivers/usb/core/message.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
> index 276768f47558..a738d03c23ea 100644
> --- a/drivers/usb/core/message.c
> +++ b/drivers/usb/core/message.c
> @@ -2209,6 +2209,11 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
>  		pm_runtime_no_callbacks(&intf->dev);
>  		dev_set_name(&intf->dev, "%d-%s:%d.%d", dev->bus->busnum,
>  				dev->devpath, configuration, ifnum);
> +		/*
> +		 * Make sure the interface does not outlive its parent (e.g.
> +		 * as needed for usb_queue_reset_device() and
> +		 * usb_if_device_type->need_parent_lock).
> +		 */
>  		usb_get_dev(dev);
>  	}
>  	kfree(new_interfaces);
> -- 
> 2.55.0


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

* Re: [PATCH] USB: core: document purpose of interface parent reference
  2026-10-15  8:08 ` Danilo Krummrich
@ 2026-10-15  8:28   ` Johan Hovold
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2026-10-15  8:28 UTC (permalink / raw)
  To: Danilo Krummrich; +Cc: Greg Kroah-Hartman, Alan Stern, linux-usb, linux-kernel

On Thu, Oct 15, 2026 at 10:08:36AM +0200, Danilo Krummrich wrote:
> On Thu Oct 15, 2026 at 9:48 AM CEST, Johan Hovold wrote:
> > USB interfaces hold a reference to their parent USB device to make sure
> > they do not outlive the parent.
> >
> > Add a comment explaining that this reference is specifically needed for
> > asynchronous device resets and the device type need_parent_lock feature
> > (to allow driver core to lock the parent when only holding a reference
> > to the interface).
> >
> > See commits:
> >
> >   524134d42231 ("USB: don't cancel queued resets when unbinding drivers")
> >   af61396a992b ("driver core: fix parent lock use-after-free on USB disconnect")
> >
> > for further details.
> >
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> 
> NIT: Maybe add that the reference count must be held until release().

I think that's implied as the comment refers to the lifetime of these
objects.

> In any case,
> 
> Reviewed-by: Danilo Krummrich <dakr@kernel.org>

Thanks for reviewing.

> > @@ -2209,6 +2209,11 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
> >  		pm_runtime_no_callbacks(&intf->dev);
> >  		dev_set_name(&intf->dev, "%d-%s:%d.%d", dev->bus->busnum,
> >  				dev->devpath, configuration, ifnum);
> > +		/*
> > +		 * Make sure the interface does not outlive its parent (e.g.
> > +		 * as needed for usb_queue_reset_device() and
> > +		 * usb_if_device_type->need_parent_lock).
> > +		 */
> >  		usb_get_dev(dev);
> >  	}

Johan

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

end of thread, other threads:[~2026-10-15  8:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-15  7:48 [PATCH] USB: core: document purpose of interface parent reference Johan Hovold
2026-10-15  8:08 ` Danilo Krummrich
2026-10-15  8:28   ` Johan Hovold

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®