History

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.

Alan Stern committed 4 years ago

Commit f6a9a2d1 parent bc25c551 file · +8 −0Browse files

Unified · Split

drivers/usb/core/usb.c+8−0
@@ -688,6 +688,10 @@ EXPORT_SYMBOL_GPL(usb_alloc_dev); · 687 unmodified lines
688688 * Drivers for USB interfaces should normally record such references in
689689 * their probe() methods, when they bind to an interface, and release
690690 * 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.
691695 *
692696 * Return: A pointer to the device with the incremented reference counter.
693697 */
@@ -722,6 +726,10 @@ EXPORT_SYMBOL_GPL(usb_put_dev); · 28 unmodified lines
722726 * Drivers for USB interfaces should normally record such references in
723727 * their probe() methods, when they bind to an interface, and release
724728 * them by calling usb_put_intf(), in their disconnect() methods.
729+ * However, if a driver does not access the usb_interface structure after
730+ * its disconnect() method returns then refcounting is not necessary,
731+ * because the USB core guarantees that a usb_interface will not be
732+ * deallocated until after its driver has been unbound.
725733 *
726734 * Return: A pointer to the interface with the incremented reference counter.
727735 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t