]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sysfs: simplify attribute definition macros
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 29 Oct 2025 08:12:16 +0000 (09:12 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2025 14:16:35 +0000 (15:16 +0100)
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>
include/linux/sysfs.h

index 592886ed6ca9e0c9aa66622cc799a73fa4e796dc..c33a96b7391a244a3f2edcee999a2e2ee8a165a7 100644 (file)
@@ -251,28 +251,20 @@ struct attribute_group {
        .store  = _store,                                               \
 }
 
-#define __ATTR_RO(_name) {                                             \
-       .attr   = { .name = __stringify(_name), .mode = 0444 },         \
-       .show   = _name##_show,                                         \
-}
-
 #define __ATTR_RO_MODE(_name, _mode) {                                 \
        .attr   = { .name = __stringify(_name),                         \
                    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) },          \
        .show   = _name##_show,                                         \
 }
 
-#define __ATTR_RW_MODE(_name, _mode) {                                 \
-       .attr   = { .name = __stringify(_name),                         \
-                   .mode = VERIFY_OCTAL_PERMISSIONS(_mode) },          \
-       .show   = _name##_show,                                         \
-       .store  = _name##_store,                                        \
-}
+#define __ATTR_RO(_name)                                               \
+       __ATTR_RO_MODE(_name, 0444)
 
-#define __ATTR_WO(_name) {                                             \
-       .attr   = { .name = __stringify(_name), .mode = 0200 },         \
-       .store  = _name##_store,                                        \
-}
+#define __ATTR_RW_MODE(_name, _mode)                                   \
+       __ATTR(_name, _mode, _name##_show, _name##_store)
+
+#define __ATTR_WO(_name)                                               \
+       __ATTR(_name, 0200, NULL, _name##_store)
 
 #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)