class_for_each_device(9)
π NAME π
class_for_each_device β device iterator. That's the whole name, and honestly? iconic. We're in the Kernel API Manual bestie, buckle up π.
β¨ SYNOPSIS β¨
int class_for_each_device (const struct class *class , const struct
device *start , void *data , device_iter_t fn );
π ARGUMENTS π
classβ the class we're iterating. Yep, the class, and its device list is about to get a whole lot of attention.startβ the device to start with in the list, if any. If you've got one, that's your starting point bestie.dataβ data for the callback. It gets passed along tofn, no cap.fnβ function to be called for each device. This is the main character callback.
π¦ DESCRIPTION π¦
Okay so picture this: we iterate over class's list of devices, and call fn for each one, passing it data. Simple. Elegant. Slay.
If start is set, the list iteration will start there. If it's NULL, the iteration starts at the beginning of the list. So like, NULL = from the top, periodt.
We check the return of fn each time. If it returns anything other than 0, we break out and return that value. Not us breaking the loop the second you return nonzero π.
fn is allowed to do anything β and I mean anything β including calling back into class code. There's no locking restriction here. That's the whole note. Do with it what you will π
.
π SEE ALSO π
- Kernel file
./drivers/base/class.c 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_find_device(9)class_compat_register(9)class_compat_unregister(9)class_compat_create_link(9)class_compat_remove_link(9)class_is_registered(9)
xoxo, your local kernel bestie π
β source/version: ./drivers/base; date: October 2026; signing off from class_for_each_device(9) π«Άβ¨
π¦ 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