usb_for_each_dev(9)
π
usb_for_each_dev β the usb_for_each_dev(9) glow-up π¦
okay so bestie, this is a page from the Kernel API Manual and it's about one tiny little function that literally walks the entire USB device list for you. no cap, it's giving "loop but make it kernel." β¨
β¨ NAME β¨
usb_for_each_dev β iterate over all USB devices in the system π
like, all of them. every single one. main character energy for your callback. π
π SYNOPSIS π
int usb_for_each_dev (void *data , int (*fn)(struct usb_device *, void
*) );
copy it exactly, bestie, don't freestyle the signature π
π ARGUMENTS π
dataβ a data pointer that will be handed to the callback function. it's your little gift bag π that gets passed straight through tofnevery time, so put whatever you want in it.fnβ the callback function to be called for each USB device. this is the whole vibe check β it gets called once per device. π
πΈ DESCRIPTION πΈ
okay so here's the tea β: usb_for_each_dev iterates over all USB devices and calls fn for each one, passing it data. simple, iconic, does exactly what it says on the tin. π
and then β plot twist π β if fn returns anything other than 0, we break the iteration prematurely and return that value right back atcha. so like, your callback can slam the brakes whenever it wants and its return value becomes the return value of the whole call. no cap, that's the escape hatch. π₯
ngl, "prematurely" is doing a lot of work in that sentence β it literally means the loop stops mid-walk and the rest of the devices never get visited. so if your fn bails on device #3, devices #4 through #β are just sitting there unvisited. π
π«Ά SEE ALSO π«Ά
Kernel file ./drivers/usb/core/usb.c β that's where the magic lives, go read it bestie π§
and the whole USB friend group, all of them, in order, don't skip anybody:
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_release_dev(9)usb_alloc_dev(9)usb_get_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)
okay that's the whole page, you ate that π β¨
quick sign-off so you have the receipts π§Ύ: this one lives under ./drivers/usb/core, dated October 2026, and it's filed as usb_for_each_dev(9). mwah, go forth and iterate π¦ππ
π¦ 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