usb_get_dev(9)
β¨ usb_get_dev(9) β¨
okay so bestie, welcome to usb_get_dev(9) β yes that's the real section number, and yes this whole page lives in the Kernel API Manual π
this is the little function that goes "hey, this USB device? mine now, don't you dare free it" π«Ά
πΈ SYNOPSIS πΈ
struct usb_device * usb_get_dev (struct usb_device *dev );
literally that's it. one argument in, one pointer out. iconic behavior, no notes π₯
π ARGUMENTS π
devβ the device being referenced π¦ like, the actualstruct usb_deviceyou're grabbing a ref on
π DESCRIPTION π
so the whole vibe here: each live reference to a device should be refcounted. that's the rule, no exceptions, we respect the refcount in this house π
drivers for USB interfaces should normally record such references in their probe methods, when they bind to an interface β and then release them by calling usb_put_dev, in their disconnect methods. balanced. symmetrical. the way that get and put mirror each other?? obsessed π
but β and this is the little plot twist β if a driver does not access the usb_device structure after its disconnect method returns, then refcounting is not necessary, because the USB core guarantees that a usb_device will not be deallocated until after all of its interface drivers have been unbound π§ so like. you're safe. the core has your back. periodt.
ngl this is the kind of detail that sounds like a throwaway line but it's lowkey the whole point β if you touch the struct after disconnect returns, you DO need the refcount. don't play yourself π
β RETURN β
a pointer to the device with the incremented reference counter π« (same device, but now it's got +1 rizz... i mean +1 refcount π)
π SEE ALSO π
kernel file ./drivers/usb/core/usb.c β and honestly the whole USB friend group showed up, so let's give them their moment:
usb_find_common_endpoints(9)usb_find_common_endpoints_reverse(9)usb_find_endpoint(9)usb_check_bulk_endpoints(9)usb_check_int_endpoints(9)usb_find_alt_setting(9)usb_ifnum_to_if(9)usb_altnum_to_altsetting(9)usb_find_interface(9)usb_for_each_dev(9)usb_release_dev(9)usb_alloc_dev(9)usb_put_dev(9)usb_get_intf(9)usb_put_intf(9)usb_intf_get_dma_device(9)usb_lock_device_for_reset(9)usb_get_current_frame_number(9)usb_alloc_coherent(9)usb_free_coherent(9)usb_alloc_noncoherent(9)usb_free_noncoherent(9)usb_endpoint_max_periodic_payload(9)usb_endpoint_is_hs_isoc_double(9)
like okay go off, entire USB subsystem π
and that's the page!! sourced from ./drivers/usb/core, stamped October 2026, and yeah the footer says usb_get_dev(9) again because the manpage format loves a little encore π mwah, go forth and refcount responsibly bestie π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms