Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: core: Update kerneldoc for usb_get_dev() and usb_get_intf()

The kerneldoc for usb_get_dev() and usb_get_intf() says that drivers
should always refcount the references they hold for the usb_device or
usb_interface structure, respectively. But this is an overstatement:
In many cases drivers do not access these references after they have
been unbound, and in such cases refcounting is unnecessary.

This patch updates the kerneldoc for the two routines, explaining when
a driver does not need to increment and decrement the refcount. This
should help dispel misconceptions which might otherwise afflict
programmers new to the USB subsystem.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/Yhjp4Rp9Alipmwtq@rowland.harvard.edu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
f6a9a2d6 bc25c558

+8
+8
drivers/usb/core/usb.c
··· 688 688 * Drivers for USB interfaces should normally record such references in 689 689 * their probe() methods, when they bind to an interface, and release 690 690 * them by calling usb_put_dev(), in their disconnect() methods. 691 + * However, if a driver does not access the usb_device structure after 692 + * its disconnect() method returns then refcounting is not necessary, 693 + * because the USB core guarantees that a usb_device will not be 694 + * deallocated until after all of its interface drivers have been unbound. 691 695 * 692 696 * Return: A pointer to the device with the incremented reference counter. 693 697 */ ··· 726 722 * Drivers for USB interfaces should normally record such references in 727 723 * their probe() methods, when they bind to an interface, and release 728 724 * them by calling usb_put_intf(), in their disconnect() methods. 725 + * However, if a driver does not access the usb_interface structure after 726 + * its disconnect() method returns then refcounting is not necessary, 727 + * because the USB core guarantees that a usb_interface will not be 728 + * deallocated until after its driver has been unbound. 729 729 * 730 730 * Return: A pointer to the interface with the incremented reference counter. 731 731 */