mirror of
https://github.com/torvalds/linux.git
synced 2026-09-25 21:21:09 -04:00
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#L497 Signed-off-by: Vincent Mailhol <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
01792c6036
commit
27ef178497
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user