DEVICE_ATTR(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… DEVICE_ATTR(9) β€” like, the kernel API manual bestie ✨

okay so this is a page from the Kernel API Manual and it's about DEVICE_ATTR, the macro that literally everybody in driver-land uses. buckle up πŸŽ€


🌸 NAME 🌸

DEVICE_ATTR β€” define a device attribute. that's it. that's the whole vibe πŸ¦‹


✨ SYNOPSIS ✨

DEVICE_ATTR (_name , _mode , _show , _store );

🫢 ARGUMENTS 🫢

  • _name β€” the attribute's name. what you're calling it, no cap πŸ’–
  • _mode β€” the file mode. permission vibes πŸ”₯
  • _show β€” the show handler. it's optional but β€” and this is the important part β€” it's mandatory if the attribute is readable. so like, optional-optional, not really πŸ™ˆ
  • _store β€” the store handler. same deal: optional, but mandatory if the attribute is writable. don't forget, bestie 😭

πŸ’… DESCRIPTION πŸ’…

it's a convenience macro for defining a struct device_attribute. that's the whole thing. it's giving "I'm a shortcut and I know it" ✨

for example, this:

DEVICE_ATTR(foo, 0644, foo_show, foo_store);

expands to this absolute icon:

struct device_attribute dev_attr_foo = {
        .attr   = { .name = "foo", .mode = 0644 },
        .show   = foo_show,
        .store  = foo_store,
};

not me writing out the struct by hand like a peasant πŸ’€ the macro ate, honestly πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

the kernel file is ./include/linux/device.h, and honestly the whole friend group is here:

like, the entire extended universe lowkey 🌈 iykyk πŸ’œ


a little sign-off from me to you: this page lives at ./include/linux, the version dates to October 2026, and it's filed under DEVICE_ATTR(9) β€” so go forth and define those device attributes, bestie, you're literally the main character of this driver πŸ§šβ€β™€οΈβœ¨πŸ’–</p>
πŸ“¦ where this page comes from