Skip to content

Commit 02ac533

Browse files
t-8chgregkh
authored andcommitted
sysfs: introduce __SYSFS_FUNCTION_ALTERNATIVE()
For the constification phase of 'struct attribute' various callback struct members will need to exist in both const and non-const variants. Keeping both members in a union avoids memory and CPU overhead but will be detected and trapped by Control Flow Integrity (CFI). By deciding between a struct and a union depending whether CFI is enabled, most configurations can avoid this overhead. Code using these callbacks will still need to be updated to handle both members explicitly. In the union case the compiler will recognize that testing for one union member is enough and optimize away the code for the other one. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20251029-sysfs-const-attr-prep-v5-3-ea7d745acff4@weissschuh.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 964c93b commit 02ac533

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

include/linux/sysfs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ do { \
5858
#define sysfs_attr_init(attr) do {} while (0)
5959
#endif
6060

61+
#ifdef CONFIG_CFI
62+
#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) struct { MEMBERS }
63+
#else
64+
#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) union { MEMBERS }
65+
#endif
66+
6167
/**
6268
* struct attribute_group - data structure used to declare an attribute group.
6369
* @name: Optional: Attribute group name

0 commit comments

Comments
 (0)