Re: [PATCH] USB: core: document purpose of interface parent reference
From: Danilo Krummrich
Date: Thu Oct 15 2026 - 04:12:55 EST
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@xxxxxxxxxx>
NIT: Maybe add that the reference count must be held until release().
In any case,
Reviewed-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> 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