Project

General

Profile

Actions

Feature #3306

open

132: Usb device reference counting with usb_get_dev/usb_put_dev and interface_to_usbdev

Added by Mikhail Mandrykin about 12 years ago. Updated almost 10 years ago.

Status:
Open
Priority:
Normal
Start date:
07/30/2012
Due date:
% Done:

0%

Estimated time:
Published in build:

Description

Proper reference counting should be performed for struct usb_device with the use of functions usb_get_dev/usb_put_dev.

/**
 * usb_get_dev - increments the reference count of the usb device structure
 * @dev: the device being referenced
 *
 * Each live reference to a device should be refcounted.
 *
 * Drivers for USB interfaces should normally record such references in
 * their probe() methods, when they bind to an interface, and release
 * them by calling usb_put_dev(), in their disconnect() methods.

Usually the reference count is increased in probe() handler and decreased in disconnect()/exit() handler. It look like interface_to_usbdev() macro is often used in probe() handler to get the reference to usb_device by the reference to usb_interface.

So the rule may be initially formalized in the following way: after acquiring a reference to struct usb_device with usb_interface macro one should increase the corresponding reference counter with usb_get_dev and then decrease it with usb_put_dev at finalization.

Links

Sample bugfixes 927c3fa

Actions

Also available in: Atom PDF