bus_to_subsys(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 bus_to_subsys β€” like, the whole vibe πŸ’…

okay so real talk, this is a page from the Kernel API Manual (yes bestie, the kernel has lore) and it's about one little function that's lowkey doing a very specific glow-up: bus_to_subsys. Let's get into it ✨


πŸŽ€ NAME πŸŽ€

bus_to_subsys β€” turns a struct bus_type into a struct subsys_private, and honestly? iconic behavior 🫢


⭐ SYNOPSIS ⭐

struct subsys_private * bus_to_subsys (const struct bus_type *bus );

like, that's the whole signature. no cap. πŸ¦‹


πŸ’– ARGUMENTS πŸ’–

  • bus β€” pointer to the struct bus_type you're trying to look up πŸ” that's the one thing you hand it.

✨ DESCRIPTION ✨

so the driver core internals are obsessed with working on the subsys_private structure β€” like, they literally cannot function on the external struct bus_type pointer. it's giving main character energy but for the internal struct, periodt. πŸ’€

what this function does is walk the list of registered busses in the system, find the matching one, and return the internal struct subsys_private that relates to that bus. it's a whole matching game, and yes, it slays. πŸ‘‘

⚠️ okay bestie, important caveat time β€” the reference count of the return value is INCREMENTED if it is not NULL. so when you're done with the pointer you must call subsys_put in order for it to be properly freed. not me forgetting this and leaking memory πŸ™ˆ don't be like me fr fr.

🌈 SEE ALSO 🌈

the kernel file ./drivers/base/bus.c is where it all lives, and there's a whole friend group of related functions β€” all of these made the list, every single one, no skips:

bus_for_each_dev(9), bus_find_device(9), bus_for_each_drv(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 whole page, bestie β€” stay hydrated, release your refcounts, and remember: this one's coming at you from ./drivers/base, dated October 2026. mwah πŸ’œπŸŽ€πŸ’…

πŸ“¦ where this page comes from