summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2026-07-07 18:56:34 +0200
committerDanilo Krummrich <dakr@kernel.org>2026-07-11 20:38:01 +0200
commited96337a5baeae5eec8ed16f8c614dc316640680 (patch)
treeea5b232f97d0e78137a805afad113ad05dbac6e4 /include/linux
parenta3a9c7453fd512e1700d63563fcd316b7795148d (diff)
downloadlinux-next-ed96337a5baeae5eec8ed16f8c614dc316640680.tar.gz
linux-next-ed96337a5baeae5eec8ed16f8c614dc316640680.zip
kobject: Allow the constification of kobject attributes
Allow kobject attribute to reside in read-only memory. Both const and non-const attributes are handled by the utility macros and attributes can be migrated one-by-one. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20260707-sysfs-const-attr-kobj-attr-prep-v2-3-35ae1bc0f9ef@weissschuh.net Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/kobject.h57
1 files changed, 51 insertions, 6 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 13bd0e87af7b..55e37a5d405e 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -138,17 +138,62 @@ struct kset_uevent_ops {
struct kobj_attribute {
struct attribute attr;
- ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
- char *buf);
- ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
- const char *buf, size_t count);
+ __SYSFS_FUNCTION_ALTERNATIVE(
+ ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
+ ssize_t (*show_const)(struct kobject *kobj, const struct kobj_attribute *attr,
+ char *buf);
+ );
+ __SYSFS_FUNCTION_ALTERNATIVE(
+ ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count);
+ ssize_t (*store_const)(struct kobject *kobj, const struct kobj_attribute *attr,
+ const char *buf, size_t count);
+ );
};
+typedef ssize_t __kobj_show_handler_const(struct kobject *kobj, const struct kobj_attribute *attr,
+ char *buf);
+typedef ssize_t __kobj_store_handler_const(struct kobject *kobj, const struct kobj_attribute *attr,
+ const char *buf, size_t count);
+
+#ifdef CONFIG_CFI
+
+#define __KOBJ_ATTR_SHOW_STORE(_show, _store) \
+ .show = _Generic(_show, \
+ __kobj_show_handler_const * : NULL, \
+ default : _show \
+ ), \
+ .show_const = _Generic(_show, \
+ __kobj_show_handler_const * : _show, \
+ default : NULL \
+ ), \
+ .store = _Generic(_store, \
+ __kobj_store_handler_const * : NULL, \
+ default : _store \
+ ), \
+ .store_const = _Generic(_store, \
+ __kobj_store_handler_const * : _store, \
+ default : NULL \
+ ),
+
+#else
+
+#define __KOBJ_ATTR_SHOW_STORE(_show, _store) \
+ .show = _Generic(_show, \
+ __kobj_show_handler_const * : (void *)_show, \
+ default : _show \
+ ), \
+ .store = _Generic(_store, \
+ __kobj_store_handler_const * : (void *)_store, \
+ default : _store \
+ ), \
+
+#endif
+
#define __KOBJ_ATTR(_name, _mode, _show, _store) { \
.attr = { .name = __stringify(_name), \
.mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
- .show = _show, \
- .store = _store, \
+ __KOBJ_ATTR_SHOW_STORE(_show, _store) \
}
#define __KOBJ_ATTR_RO_MODE(_name, _mode) \