DEVICE_ATTR(9)
π 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:
struct subsys_interface(9)struct device_attribute(9)struct dev_ext_attribute(9)DEVICE_ATTR_RW(9)DEVICE_ATTR_ADMIN_RW(9)DEVICE_ATTR_RW_NAMED(9)DEVICE_ATTR_RO(9)DEVICE_ATTR_ADMIN_RO(9)DEVICE_ATTR_RO_NAMED(9)DEVICE_ATTR_WO(9)DEVICE_ATTR_WO_NAMED(9)DEVICE_ULONG_ATTR(9)DEVICE_INT_ATTR(9)DEVICE_BOOL_ATTR(9)DEVICE_STRING_ATTR_RO(9)enum device_link_state(9)enum dl_dev_state(9)enum device_removable(9)struct dev_links_info(9)struct dev_msi_info(9)enum device_physical_location_panel(9)enum device_physical_location_vertical_position(9)enum device_physical_location_horizontal_position(9)struct device_physical_location(9)enum struct_device_flags(9)struct device(9)struct device_link(9)device_set_driver_override(9)device_has_driver_override(9)device_match_driver_override(9)device_iommu_mapped(9)dev_name(9)dev_bus_name(9)device_find_child_by_name(9)device_find_any_child(9)device_lock_set_class(9)device_lock_reset_class(9)
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 underDEVICE_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
- 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