From 418a74d106ef4fe08fe9eb239e8b9717b3d79ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 7 Jul 2026 18:56:32 +0200 Subject: [PATCH] kobject: Provide macros to initialize 'struct kobj_attribute' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Link: https://patch.msgid.link/20260707-sysfs-const-attr-kobj-attr-prep-v2-1-35ae1bc0f9ef@weissschuh.net Signed-off-by: Danilo Krummrich --- include/linux/kobject.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index bcb5d4e32001..13bd0e87af7b 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;