Skip to content

Commit 7146494

Browse files
t-8chgregkh
authored andcommitted
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>
1 parent 2d76fdc commit 7146494

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

include/linux/sysfs.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,28 +251,20 @@ struct attribute_group {
251251
.store = _store, \
252252
}
253253

254-
#define __ATTR_RO(_name) { \
255-
.attr = { .name = __stringify(_name), .mode = 0444 }, \
256-
.show = _name##_show, \
257-
}
258-
259254
#define __ATTR_RO_MODE(_name, _mode) { \
260255
.attr = { .name = __stringify(_name), \
261256
.mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
262257
.show = _name##_show, \
263258
}
264259

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)
271262

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)
276268

277269
#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)
278270

0 commit comments

Comments
 (0)