]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sysfs: implement all BIN_ATTR_* macros in terms of __BIN_ATTR()
authorThomas Weißschuh <linux@weissschuh.net>
Sun, 3 Nov 2024 17:03:37 +0000 (17:03 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 5 Nov 2024 13:00:28 +0000 (14:00 +0100)
The preparations for the upcoming constification of struct bin_attribute
requires some logic in the structure definition macros.
To avoid duplication of that logic in multiple macros, reimplement all
other macros in terms of __BIN_ATTR().

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Krzysztof Wilczyński <kw@linux.com>
Link: https://lore.kernel.org/r/20241103-sysfs-const-bin_attr-v2-8-71110628844c@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/sysfs.h

index cb2a5e277c2384f2e8add8fbf2907e8a819576ec..d17c473c1ef292875475bf3bdf62d07241c13882 100644 (file)
@@ -333,17 +333,11 @@ struct bin_attribute {
        .size   = _size,                                                \
 }
 
-#define __BIN_ATTR_RO(_name, _size) {                                  \
-       .attr   = { .name = __stringify(_name), .mode = 0444 },         \
-       .read   = _name##_read,                                         \
-       .size   = _size,                                                \
-}
+#define __BIN_ATTR_RO(_name, _size)                                    \
+       __BIN_ATTR(_name, 0444, _name##_read, NULL, _size)
 
-#define __BIN_ATTR_WO(_name, _size) {                                  \
-       .attr   = { .name = __stringify(_name), .mode = 0200 },         \
-       .write  = _name##_write,                                        \
-       .size   = _size,                                                \
-}
+#define __BIN_ATTR_WO(_name, _size)                                    \
+       __BIN_ATTR(_name, 0200, NULL, _name##_write, _size)
 
 #define __BIN_ATTR_RW(_name, _size)                                    \
        __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
@@ -364,11 +358,8 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
 
 
-#define __BIN_ATTR_ADMIN_RO(_name, _size) {                                    \
-       .attr   = { .name = __stringify(_name), .mode = 0400 },         \
-       .read   = _name##_read,                                         \
-       .size   = _size,                                                \
-}
+#define __BIN_ATTR_ADMIN_RO(_name, _size)                              \
+       __BIN_ATTR(_name, 0400, _name##_read, NULL, _size)
 
 #define __BIN_ATTR_ADMIN_RW(_name, _size)                                      \
        __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size)
@@ -379,10 +370,8 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size)
 #define BIN_ATTR_ADMIN_RW(_name, _size)                                        \
 struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size)
 
-#define __BIN_ATTR_SIMPLE_RO(_name, _mode) {                           \
-       .attr   = { .name = __stringify(_name), .mode = _mode },        \
-       .read   = sysfs_bin_attr_simple_read,                           \
-}
+#define __BIN_ATTR_SIMPLE_RO(_name, _mode)                             \
+       __BIN_ATTR(_name, _mode, sysfs_bin_attr_simple_read, NULL, 0)
 
 #define BIN_ATTR_SIMPLE_RO(_name)                                      \
 struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0444)