Feature #3306

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

Added by Mikhail Mandrykin over 9 years ago. Updated about 7 years ago.

Start date:
Due date:
% Done:


Estimated time:
Published in build:


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.


Sample bugfixes 927c3fa


Updated by Mikhail Mandrykin over 9 years ago

  • Assignee set to Mikhail Mandrykin

Updated by Mikhail Mandrykin over 9 years ago

  • Status changed from New to Open

Updated by Vitaly Mordan about 7 years ago

Unnecessary header
#include <linux/usb.h>
may cause Aspectator to failed at 'instrumentation' stage.


Updated by Vadim Mutilin about 7 years ago

  • Description updated (diff)

Also available in: Atom PDF