]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sysfs: transparently handle const pointers in ATTRIBUTE_GROUPS()
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 29 Oct 2025 08:12:11 +0000 (09:12 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2025 14:16:35 +0000 (15:16 +0100)
To ease the constification process of 'struct attribute', transparently
handle the const pointers in ATTRIBUTE_GROUPS(). A cast is used instead
of assigning to .attrs_new as it keeps the macro smaller. As both
members are aliased to each other the result is identical.

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

index e34d6af96abb6aebf8b256ad13b18d652ff9291b..92f82cee5f11e98652e5b5fc1e69cd6e9e97833a 100644 (file)
@@ -287,7 +287,12 @@ static const struct attribute_group *_name##_groups[] = {  \
 
 #define ATTRIBUTE_GROUPS(_name)                                        \
 static const struct attribute_group _name##_group = {          \
-       .attrs = _name##_attrs,                                 \
+       .attrs = _Generic(_name##_attrs,                        \
+                         struct attribute **:                  \
+                               _name##_attrs,                  \
+                         const struct attribute *const *:      \
+                               (void *)_name##_attrs           \
+       ),                                                      \
 };                                                             \
 __ATTRIBUTE_GROUPS(_name)