Commit 27ef1784 authored by Vincent Mailhol's avatar Vincent Mailhol Committed by Greg Kroah-Hartman

usb: add usb_set_intfdata() documentation

USB drivers do not need to call usb_set_intfdata(intf, NULL) in their
usb_driver::disconnect callback because the core already does it in [1].

However, this fact is widely unknown, c.f.:

  $ git grep "usb_set_intfdata(.*NULL)" | wc -l
  215

Especially, setting the interface to NULL before all action completed
can result in a NULL pointer dereference. Not calling
usb_set_intfdata() at all in disconnect() is the safest method.

Add documentation to usb_set_intfdata() to clarify this point.

Also remove the call in usb-skeletion's disconnect() not to confuse
the new comers.

[1] function usb_unbind_interface() from drivers/usb/core/driver.c
Link: https://elixir.bootlin.com/linux/v6.0/source/drivers/usb/core/driver.c#L497Signed-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/r/20221128102954.3615579-1-mailhol.vincent@wanadoo.frSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 01792c60
......@@ -564,7 +564,6 @@ static void skel_disconnect(struct usb_interface *interface)
int minor = interface->minor;
dev = usb_get_intfdata(interface);
usb_set_intfdata(interface, NULL);
/* give back our minor */
usb_deregister_dev(interface, &skel_class);
......
......@@ -265,6 +265,18 @@ static inline void *usb_get_intfdata(struct usb_interface *intf)
return dev_get_drvdata(&intf->dev);
}
/**
* usb_set_intfdata() - associate driver-specific data with the interface
* @intf: the usb interface
* @data: pointer to the device priv structure or %NULL
*
* Drivers should use this function in their probe() to associate their
* driver-specific data with the usb interface.
*
* When disconnecting, the core will take care of setting @intf back to %NULL,
* so no actions are needed on the driver side. The interface should not be set
* to %NULL before all actions completed (e.g. no outsanding URB remaining).
*/
static inline void usb_set_intfdata(struct usb_interface *intf, void *data)
{
dev_set_drvdata(&intf->dev, data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment