class_for_each_device(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 to fn, 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 🌈


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