From 55389a4354a643492bd0f6b2a06c6e510c4e7905 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Thu, 16 Jul 2026 19:09:27 +0200 Subject: configfs: Constify is_visible/is_visible_bin in configfs_group_operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These callbacks are never meant to modify their configfs_attribute structure. Enforce this in the type system. As there are only two implementers of these callbacks, adapt them right away, avoiding a phased transition. Signed-off-by: Thomas Weißschuh Reviewed-by: Breno Leitao Acked-by: Andreas Hindborg Link: https://patch.msgid.link/20260716-configfs-const-base-v1-2-c545a4053cb5@weissschuh.net Signed-off-by: Breno Leitao --- include/linux/configfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/linux') diff --git a/include/linux/configfs.h b/include/linux/configfs.h index ef65c75beeaa..5d3fc8822a1d 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -220,8 +220,8 @@ struct configfs_group_operations { struct config_group *(*make_group)(struct config_group *group, const char *name); void (*disconnect_notify)(struct config_group *group, struct config_item *item); void (*drop_item)(struct config_group *group, struct config_item *item); - bool (*is_visible)(struct config_item *item, struct configfs_attribute *attr, int n); - bool (*is_bin_visible)(struct config_item *item, struct configfs_bin_attribute *attr, + bool (*is_visible)(struct config_item *item, const struct configfs_attribute *attr, int n); + bool (*is_bin_visible)(struct config_item *item, const struct configfs_bin_attribute *attr, int n); }; -- cgit v1.2.3 From ee4f267ada12bd5eb8b675018bdd60e60da2c089 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Thu, 16 Jul 2026 19:09:29 +0200 Subject: configfs: Constify configfs_bin_attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The configfs_bin_attribute structures defined by driver are never modified. Make them const. As there are only two users of these attributes, adapt them in the same commit to avoid a phased transition. Signed-off-by: Thomas Weißschuh Acked-by: Andreas Hindborg Link: https://patch.msgid.link/20260716-configfs-const-base-v1-4-c545a4053cb5@weissschuh.net Signed-off-by: Breno Leitao --- drivers/acpi/acpi_configfs.c | 2 +- drivers/virt/coco/guest/report.c | 2 +- include/linux/configfs.h | 64 ++++++++++++++++++++-------------------- rust/kernel/configfs.rs | 4 +-- 4 files changed, 36 insertions(+), 36 deletions(-) (limited to 'include/linux') diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c index 12ffec795803..6071699c7165 100644 --- a/drivers/acpi/acpi_configfs.c +++ b/drivers/acpi/acpi_configfs.c @@ -91,7 +91,7 @@ static ssize_t acpi_table_aml_read(struct config_item *cfg, CONFIGFS_BIN_ATTR(acpi_table_, aml, NULL, MAX_ACPI_TABLE_SIZE); -static struct configfs_bin_attribute *acpi_table_bin_attrs[] = { +static const struct configfs_bin_attribute *const acpi_table_bin_attrs[] = { &acpi_table_attr_aml, NULL, }; diff --git a/drivers/virt/coco/guest/report.c b/drivers/virt/coco/guest/report.c index 96e89ddf4989..ad400fbe53f0 100644 --- a/drivers/virt/coco/guest/report.c +++ b/drivers/virt/coco/guest/report.c @@ -356,7 +356,7 @@ static struct configfs_attribute *tsm_report_attrs[] = { NULL, }; -static struct configfs_bin_attribute *tsm_report_bin_attrs[] = { +static const struct configfs_bin_attribute *const tsm_report_bin_attrs[] = { [TSM_REPORT_INBLOB] = &tsm_report_attr_inblob, [TSM_REPORT_OUTBLOB] = &tsm_report_attr_outblob, [TSM_REPORT_AUXBLOB] = &tsm_report_attr_auxblob, diff --git a/include/linux/configfs.h b/include/linux/configfs.h index 5d3fc8822a1d..eff2fb22ab70 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -67,7 +67,7 @@ struct config_item_type { const struct configfs_item_operations *ct_item_ops; const struct configfs_group_operations *ct_group_ops; struct configfs_attribute **ct_attrs; - struct configfs_bin_attribute **ct_bin_attrs; + const struct configfs_bin_attribute *const *ct_bin_attrs; }; /** @@ -160,41 +160,41 @@ struct configfs_bin_attribute { ssize_t (*write)(struct config_item *, const void *, size_t); }; -#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \ -static struct configfs_bin_attribute _pfx##attr_##_name = { \ - .cb_attr = { \ - .ca_name = __stringify(_name), \ - .ca_mode = S_IRUGO | S_IWUSR, \ - .ca_owner = THIS_MODULE, \ - }, \ - .cb_private = _priv, \ - .cb_max_size = _maxsz, \ - .read = _pfx##_name##_read, \ - .write = _pfx##_name##_write, \ +#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \ +static const struct configfs_bin_attribute _pfx##attr_##_name = { \ + .cb_attr = { \ + .ca_name = __stringify(_name), \ + .ca_mode = S_IRUGO | S_IWUSR, \ + .ca_owner = THIS_MODULE, \ + }, \ + .cb_private = _priv, \ + .cb_max_size = _maxsz, \ + .read = _pfx##_name##_read, \ + .write = _pfx##_name##_write, \ } -#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \ -static struct configfs_bin_attribute _pfx##attr_##_name = { \ - .cb_attr = { \ - .ca_name = __stringify(_name), \ - .ca_mode = S_IRUGO, \ - .ca_owner = THIS_MODULE, \ - }, \ - .cb_private = _priv, \ - .cb_max_size = _maxsz, \ - .read = _pfx##_name##_read, \ +#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \ +static const struct configfs_bin_attribute _pfx##attr_##_name = { \ + .cb_attr = { \ + .ca_name = __stringify(_name), \ + .ca_mode = S_IRUGO, \ + .ca_owner = THIS_MODULE, \ + }, \ + .cb_private = _priv, \ + .cb_max_size = _maxsz, \ + .read = _pfx##_name##_read, \ } -#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \ -static struct configfs_bin_attribute _pfx##attr_##_name = { \ - .cb_attr = { \ - .ca_name = __stringify(_name), \ - .ca_mode = S_IWUSR, \ - .ca_owner = THIS_MODULE, \ - }, \ - .cb_private = _priv, \ - .cb_max_size = _maxsz, \ - .write = _pfx##_name##_write, \ +#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \ +static const struct configfs_bin_attribute _pfx##attr_##_name = { \ + .cb_attr = { \ + .ca_name = __stringify(_name), \ + .ca_mode = S_IWUSR, \ + .ca_owner = THIS_MODULE, \ + }, \ + .cb_private = _priv, \ + .cb_max_size = _maxsz, \ + .write = _pfx##_name##_write, \ } /* diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 5c66b7e4b109..5052c1bbaf94 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -757,7 +757,7 @@ macro_rules! impl_item_type { ct_group_ops: GroupOperationsVTable::::vtable_ptr(), ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(), ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(), - ct_bin_attrs: core::ptr::null_mut(), + ct_bin_attrs: core::ptr::null(), }), _p: PhantomData, } @@ -774,7 +774,7 @@ macro_rules! impl_item_type { ct_group_ops: core::ptr::null(), ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(), ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(), - ct_bin_attrs: core::ptr::null_mut(), + ct_bin_attrs: core::ptr::null(), }), _p: PhantomData, } -- cgit v1.2.3 From f7528cd38b87fb59b6e5f96abfd119f0318a52e4 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Thu, 16 Jul 2026 19:09:30 +0200 Subject: 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(-) (limited to 'include/linux') 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 @@ macro_rules! impl_item_type { 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 @@ macro_rules! impl_item_type { 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, -- cgit v1.2.3