Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sysfs: simplify attribute definition macros

Define the macros in terms of each other.
This makes them easier to understand and also will make it easier to
implement the transition machinery for 'const struct attribute'.

__ATTR_RO_MODE() can't be implemented in terms of __ATTR() as not all
attributes have a .store callback. The same issue theoretically exists
for __ATTR_WO(), but practically that does not occur today.

Reorder __ATTR_RO() below __ATTR_RO_MODE() to keep the order of the
macro definition consistent with respect to each other.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://patch.msgid.link/20251029-sysfs-const-attr-prep-v5-7-ea7d745acff4@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
71464949 2d76fdc1

+7 -15
+7 -15
include/linux/sysfs.h
··· 251 251 .store = _store, \ 252 252 } 253 253 254 - #define __ATTR_RO(_name) { \ 255 - .attr = { .name = __stringify(_name), .mode = 0444 }, \ 256 - .show = _name##_show, \ 257 - } 258 - 259 254 #define __ATTR_RO_MODE(_name, _mode) { \ 260 255 .attr = { .name = __stringify(_name), \ 261 256 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 262 257 .show = _name##_show, \ 263 258 } 264 259 265 - #define __ATTR_RW_MODE(_name, _mode) { \ 266 - .attr = { .name = __stringify(_name), \ 267 - .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 268 - .show = _name##_show, \ 269 - .store = _name##_store, \ 270 - } 260 + #define __ATTR_RO(_name) \ 261 + __ATTR_RO_MODE(_name, 0444) 271 262 272 - #define __ATTR_WO(_name) { \ 273 - .attr = { .name = __stringify(_name), .mode = 0200 }, \ 274 - .store = _name##_store, \ 275 - } 263 + #define __ATTR_RW_MODE(_name, _mode) \ 264 + __ATTR(_name, _mode, _name##_show, _name##_store) 265 + 266 + #define __ATTR_WO(_name) \ 267 + __ATTR(_name, 0200, NULL, _name##_store) 276 268 277 269 #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) 278 270