From f7528cd38b87fb59b6e5f96abfd119f0318a52e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Thu, 16 Jul 2026 19:09:30 +0200 Subject: [PATCH] configfs: Allow the registration of const struct configfs_attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The attribute structure defined in driver code never need to be modified. Allow them to be marked as const. As there are many drivers which use these attributes, prepare for a phased transition by using a union of const and non-const attributes. After all drivers have been migrated to the const variant, the non-const one can be replaced by the const one and the transition machinery will be removed again. Signed-off-by: Thomas Weißschuh Acked-by: Andreas Hindborg Link: https://patch.msgid.link/20260716-configfs-const-base-v1-5-c545a4053cb5@weissschuh.net Signed-off-by: Breno Leitao --- fs/configfs/dir.c | 4 ++-- include/linux/configfs.h | 5 ++++- rust/kernel/configfs.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index 655e361b27a8..cb45e151d852 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -641,8 +641,8 @@ static int populate_attrs(struct config_item *item) ops = t->ct_group_ops; - if (t->ct_attrs) { - for (i = 0; (attr = t->ct_attrs[i]) != NULL; i++) { + if (t->ct_attrs_const) { + for (i = 0; (attr = t->ct_attrs_const[i]) != NULL; i++) { if (ops && ops->is_visible && !ops->is_visible(item, attr, i)) continue; diff --git a/include/linux/configfs.h b/include/linux/configfs.h index eff2fb22ab70..5bead9173ec1 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -66,7 +66,10 @@ struct config_item_type { struct module *ct_owner; const struct configfs_item_operations *ct_item_ops; const struct configfs_group_operations *ct_group_ops; - struct configfs_attribute **ct_attrs; + union { + struct configfs_attribute **ct_attrs; + const struct configfs_attribute *const *ct_attrs_const; + }; const struct configfs_bin_attribute *const *ct_bin_attrs; }; diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 5052c1bbaf94..0be10cf61927 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -756,7 +756,9 @@ pub const fn new_with_child_ctor( ct_owner: owner.as_ptr(), ct_group_ops: GroupOperationsVTable::::vtable_ptr(), ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(), - ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(), + __bindgen_anon_1: bindings::config_item_type__bindgen_ty_1 { + ct_attrs_const: core::ptr::from_ref(attributes).cast(), + }, ct_bin_attrs: core::ptr::null(), }), _p: PhantomData, @@ -773,7 +775,9 @@ pub const fn new( ct_owner: owner.as_ptr(), ct_group_ops: core::ptr::null(), ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(), - ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(), + __bindgen_anon_1: bindings::config_item_type__bindgen_ty_1 { + ct_attrs_const: core::ptr::from_ref(attributes).cast(), + }, ct_bin_attrs: core::ptr::null(), }), _p: PhantomData,