class_find_device(9)
π class_find_device β bestie's guide to finding one specific device
ok so real talk, you're in the Kernel API Manual (section 9, kernel internals, iykyk) and the function we're stanning today is class_find_device, and honestly? it's giving "where's that one device" energy. it's the device iterator that goes looking for a particular device instead of just vibing through the whole class. let's get into it π
β¨ SYNOPSIS β¨
struct device * class_find_device (const struct class *class , const
struct device *start , const void *data , device_match_t match );
like, four args, one struct device * back. clean. iconic. no notes. πΈ
π«Ά ARGUMENTS π«Ά
classβ the class we're iterating, aka the friend group we're scrolling through πstartβ Device to begin with, aka where you start scrolling from (yes, literally the starting device)dataβ data for the match function β this is the little care package you hand to your callback so it knows what it's looking for πmatchβ function to check device β the vibe check callback, the one who decides who's the one π₯
π DESCRIPTION π
so this is similar to the class_for_each_dev function above, but instead of just doing a drive-by over everything, it returns a reference to a device that is 'found' for later use, as determined by the match callback. so you're not just visiting β you're keeping one. main character device energy fr fr π
the callback should return 0 if the device doesn't match and non-zero if it does. if the callback returns non-zero, this function will return to the caller and not iterate over any more devices β it's done, it found its person, the search is over, periodt π¦
β οΈ okay bestie listen β you will need to drop the reference with put_device after use. do not forget. do not leave it hanging. that's a refcount leak and we do NOT do that in this house π
and here's the cute part: match is allowed to do anything including calling back into class code. there's no locking restriction. no cap. go wild. π
π SEE ALSO π
Kernel file ./drivers/base/class.c β and the whole squad:
class_to_subsys(9)class_create(9)class_destroy(9)class_dev_iter_init(9)class_dev_iter_next(9)class_dev_iter_exit(9)class_for_each_device(9)class_compat_register(9)class_compat_unregister(9)class_compat_create_link(9)class_compat_remove_link(9)class_is_registered(9)
and that's the whole page, bestie π this lil slice of kernel knowledge lives in ./drivers/base, stamped October 2026, under the class_find_device(9) banner β go forth, find your device, and remember to put_device π«Άβ¨
π¦ 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