bus_for_each_drv(9)
π bus_for_each_drv(9) β the driver iterator, bestie
okay so this is a page from the Kernel API Manual, section 9, and it's literally all about bus_for_each_drv π¦ like that's the whole vibe. it's a driver iterator. yep. that's the name, that's the game β¨
πΈ SYNOPSIS πΈ
int bus_for_each_drv (const struct bus_type *bus , struct device_driver
*start , void *data , int (*fn)(struct device_driver *, void *) );
copy it exactly, don't get cute with it π
π ARGUMENTS π
busβ the bus we're dealing with. the main character of this whole operation πstartβ the driver to start iterating on. where the scroll begins π«Άdataβ data to pass to the callback. the little gift bag you hand over πfnβ the function to call for each driver. your callback, your rules, your moment π
β¨ DESCRIPTION β¨
so this one is nearly identical to the device iterator above (iykyk β go read that one too, bestie). we iterate over each driver that belongs to bus, and we call fn for each one. every single one. no skipping π§
if fn returns anything but 0, we break out and return it. like, we're done, we're leaving, that's the exit signal π₯
and if start is not NULL, we use it as the head of the list. so you get to pick where the party starts π
π NOTE π
okay important, bestie, listen up for this one π
we don't return the driver that returns a non-zero value β like, the driver that made us bail? it doesn't come back to you. and we also don't leave the reference count incremented for that driver. nope, not a thing π
so if the caller needs to know that info, it must set it in the callback. periodt. and it must also be sure to increment the refcount so it doesn't disappear before returning to the caller. like actually β otherwise it could vanish on you before you even get back to the caller π don't do that to yourself.
π¦ SEE ALSO π¦
Kernel file ./drivers/base/bus.c:
bus_to_subsys(9)bus_for_each_dev(9)bus_find_device(9)bus_add_device(9)bus_probe_device(9)bus_remove_device(9)bus_add_driver(9)bus_remove_driver(9)bus_rescan_devices(9)device_reprobe(9)bus_register(9)bus_unregister(9)subsys_dev_iter_init(9)subsys_dev_iter_next(9)subsys_dev_iter_exit(9)subsys_system_register(9)subsys_virtual_register(9)driver_find(9)bus_get_dev_root(9)
and that's the page, bestie π«Ά this lil icon lives at ./drivers/base and it's dated October 2026 β slay, see you in the source tree π
π¦ 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