[PATCH 1/4] kobject: Provide macros to initialize 'struct kobj_attribute'
From: Thomas Weißschuh
Date: Fri May 29 2026 - 12:44:33 EST
Currently the generic __ATTR*() macros are used to initialize kobject
attributes. These are not able to handle the upcoming piece-by-piece
constification of the attribute callback handlers.
Add dedicated macros of kobject attributes. For now these are the same
as the generic macros, but they will change soon. Users will be
converted to these macros as part of the constification, but it is
expected that they will be used generally in the future.
Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
include/linux/kobject.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bcb5d4e32001..975a5361fb60 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -144,6 +144,28 @@ struct kobj_attribute {
const char *buf, size_t count);
};
+#define __KOBJ_ATTR(_name, _mode, _show, _store) { \
+ .attr = { .name = __stringify(_name), \
+ .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
+ .show = _show, \
+ .store = _store, \
+}
+
+#define __KOBJ_ATTR_RO_MODE(_name, _mode) { \
+ __KOBJ_ATTR(_name, _mode, _name##_show, NULL)
+
+#define __KOBJ_ATTR_RO(_name) \
+ __KOBJ_ATTR_RO_MODE(_name, 0444)
+
+#define __KOBJ_ATTR_RW_MODE(_name, _mode) \
+ __KOBJ_ATTR(_name, _mode, _name##_show, _name##_store)
+
+#define __KOBJ_ATTR_WO(_name) \
+ __KOBJ_ATTR(_name, 0200, NULL, _name##_store)
+
+#define __KOBJ_ATTR_RW(_name) \
+ __KOBJ_ATTR(_name, 0644, _name##_show, _name##_store)
+
extern const struct sysfs_ops kobj_sysfs_ops;
struct sock;
--
2.54.0