Skip to contentSkip to conversation

configfs: Constify some fileds in struct config_item_type

PATCH Applied Christophe JAILLET 3 participants 9 messages Oct 25, 2025 – Nov 27, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover configfs: Constify some fileds in struct config_item_type

These 2 patches constify ct_item_ops and ct_group_ops in struct config_item_type.

When/if they are applied, I'll send some patchess in each subsystem to constify the corresponding structures.

This 2 steps approach is IMHO easier way to make these changes. This avoids long series and cover-letter/first patches sent to many maintainers and lists.

However, if you prefer things to be done in the same serie, I can do that as well.

Christophe JAILLET (2):
configfs: Constify ct_group_ops in struct config_item_type
configfs: Constify ct_item_ops in struct config_item_type

 fs/configfs/dir.c        | 2 +-
 fs/configfs/file.c       | 2 +-
 include/linux/configfs.h | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/2 configfs: Constify ct_group_ops in struct config_item_type

Make 'ct_group_ops' const in struct config_item_type.
This allows constification of many structures which hold some function pointers.

---
Compile tested only files that explicitly use ct_group_ops.

The script used for that is:
while IFS= read -r -d '' file; do

    obj="${file%.c}.o" ; echo -e "\nCompiling $file" ; make "$obj"
  done < <(git grep --name-only -z ct_group_ops '*.c')
---
 fs/configfs/dir.c        | 2 +-
 include/linux/configfs.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/configfs/dir.c +1 -1
index 81f4f06bc87e..4bcd14b3434c 100644
@@ -598,7 +598,7 @@ static void detach_attrs(struct config_item * item)
 static int populate_attrs(struct config_item *item)
 {
 	const struct config_item_type *t = item->ci_type;
-	struct configfs_group_operations *ops;
+	const struct configfs_group_operations *ops;
 	struct configfs_attribute *attr;
 	struct configfs_bin_attribute *bin_attr;
 	int error = 0;
include/linux/configfs.h +1 -1
index 698520b1bfdb..31a7d7124460 100644
@@ -65,7 +65,7 @@ extern void config_item_put(struct config_item *);
 struct config_item_type {
 	struct module				*ct_owner;
 	struct configfs_item_operations		*ct_item_ops;
-	struct configfs_group_operations	*ct_group_ops;
+	const struct configfs_group_operations	*ct_group_ops;
 	struct configfs_attribute		**ct_attrs;
 	struct configfs_bin_attribute		**ct_bin_attrs;
 };
Signature · 1 line
2.51.0
#3 lore raw

PATCH 2/2 configfs: Constify ct_item_ops in struct config_item_type

In reply to Christophe JAILLET

Make 'ct_item_ops' const in struct config_item_type.
This allows constification of many structures which hold some function pointers.

---
Compile tested only files that explicitly use ct_group_ops.

The script used for that is:
while IFS= read -r -d '' file; do

    obj="${file%.c}.o" ; echo -e "\nCompiling $file" ; make "$obj"
  done < <(git grep --name-only -z ct_item_ops '*.c')
---
 fs/configfs/file.c       | 2 +-
 include/linux/configfs.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/configfs/file.c +1 -1
index 0ad32150611e..affe4742bbb5 100644
@@ -30,7 +30,7 @@ struct configfs_buffer {
 	size_t			count;
 	loff_t			pos;
 	char			* page;
-	struct configfs_item_operations	* ops;
+	const struct configfs_item_operations	*ops;
 	struct mutex		mutex;
 	int			needs_read_fill;
 	bool			read_in_progress;
include/linux/configfs.h +1 -1
index 31a7d7124460..ef65c75beeaa 100644
@@ -64,7 +64,7 @@ extern void config_item_put(struct config_item *);
 
 struct config_item_type {
 	struct module				*ct_owner;
-	struct configfs_item_operations		*ct_item_ops;
+	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;
Signature · 1 line
2.51.0
maintainer
#5 lore raw
In reply to Christophe JAILLET
Quoted 6 lines · Christophe JAILLET

These 2 patches constify ct_item_ops and ct_group_ops in struct config_item_type.

When/if they are applied, I'll send some patchess in each subsystem to constify the corresponding structures.

Quoted 6 lines

This 2 steps approach is IMHO easier way to make these changes. This avoids long series and cover-letter/first patches sent to many maintainers and lists.

However, if you prefer things to be done in the same serie, I can do that as well.

Looks good to me. Please also include a patch to fix up the rust bindings in the 2nd step:

rust/kernel/configfs.rs +3 -3
index 318a2f073d1c7..468c8c4170d5e 100644
@@ -755,8 +755,8 @@ pub const fn new_with_child_ctor<const N: usize, Child>(
                 Self {
                     item_type: Opaque::new(bindings::config_item_type {
                         ct_owner: owner.as_ptr(),
-                        ct_group_ops: GroupOperationsVTable::<Data, Child>::vtable_ptr().cast_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        ct_group_ops: GroupOperationsVTable::<Data, Child>::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(),
                     }),
@@ -773,7 +773,7 @@ pub const fn new<const N: usize>(
                     item_type: Opaque::new(bindings::config_item_type {
                         ct_owner: owner.as_ptr(),
                         ct_group_ops: core::ptr::null_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        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(),
                     }),

Best regards,
Andreas Hindborg

#6 lore raw

Le 29/10/2025 à 08:18, Andreas Hindborg a écrit :

Quoted 35 lines
Quoted 6 lines · Christophe JAILLET

These 2 patches constify ct_item_ops and ct_group_ops in struct config_item_type.

When/if they are applied, I'll send some patchess in each subsystem to constify the corresponding structures.

Quoted 6 lines

This 2 steps approach is IMHO easier way to make these changes. This avoids long series and cover-letter/first patches sent to many maintainers and lists.

However, if you prefer things to be done in the same serie, I can do that as well.

Looks good to me. Please also include a patch to fix up the rust bindings in the 2nd step:

rust/kernel/configfs.rs +2 -2
index 318a2f073d1c7..468c8c4170d5e 100644
@@ -755,8 +755,8 @@ pub const fn new_with_child_ctor<const N: usize, Child>(
                  Self {
                      item_type: Opaque::new(bindings::config_item_type {
                          ct_owner: owner.as_ptr(),
-                        ct_group_ops: GroupOperationsVTable::<Data, Child>::vtable_ptr().cast_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        ct_group_ops: GroupOperationsVTable::<Data, Child>::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(),
                      }),

rust/kernel/configfs.rs pub const fn new<const N: usize>( · line 779

Quoted 8 lines
rust/kernel/configfs.rs +1 -1
@@ -773,7 +773,7 @@ pub const fn new<const N: usize>(
                      item_type: Opaque::new(bindings::config_item_type {
                          ct_owner: owner.as_ptr(),
                          ct_group_ops: core::ptr::null_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        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(),
                      }),

I'm not a big fan of mixing c and rs files updates in the same commit.
And, as I don't know rust, I'm reluctant to changes things that I don't understand and I'm not able to at least compile test.

Can s.o. send this change as a follow-up patch?

CJ

Quoted 8 lines

Best regards,
Andreas Hindborg

maintainer
#7 lore raw
Quoted 40 lines · Christophe JAILLET

Le 29/10/2025 à 08:18, Andreas Hindborg a écrit :

Quoted 39 lines
Quoted 6 lines · Christophe JAILLET

These 2 patches constify ct_item_ops and ct_group_ops in struct config_item_type.

When/if they are applied, I'll send some patchess in each subsystem to constify the corresponding structures.

Quoted 6 lines

This 2 steps approach is IMHO easier way to make these changes. This avoids long series and cover-letter/first patches sent to many maintainers and lists.

However, if you prefer things to be done in the same serie, I can do that as well.

Looks good to me. Please also include a patch to fix up the rust bindings in the 2nd step:

rust/kernel/configfs.rs +3 -3
index 318a2f073d1c7..468c8c4170d5e 100644
@@ -755,8 +755,8 @@ pub const fn new_with_child_ctor<const N: usize, Child>(
                  Self {
                      item_type: Opaque::new(bindings::config_item_type {
                          ct_owner: owner.as_ptr(),
-                        ct_group_ops: GroupOperationsVTable::<Data, Child>::vtable_ptr().cast_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        ct_group_ops: GroupOperationsVTable::<Data, Child>::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(),
                      }),
@@ -773,7 +773,7 @@ pub const fn new<const N: usize>(
                      item_type: Opaque::new(bindings::config_item_type {
                          ct_owner: owner.as_ptr(),
                          ct_group_ops: core::ptr::null_mut(),
-                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr().cast_mut(),
+                        ct_item_ops: ItemOperationsVTable::<$tpe, Data>::vtable_ptr(),
Quoted 8 lines

rust/kernel/configfs.rs pub const fn new_with_child_ctor<const N: usize, Child>( · line 762

Quoted 4 lines
rust/kernel/configfs.rs +0 -0
                          ct_attrs: core::ptr::from_ref(attributes).cast_mut().cast(),
                          ct_bin_attrs: core::ptr::null_mut(),
                      }),

I'm not a big fan of mixing c and rs files updates in the same commit. And, as I don't know rust, I'm reluctant to changes things that I don't understand and I'm not able to at least compile test.

This is why I gave you the diff.

Quoted 2 lines

Can s.o. send this change as a follow-up patch?

Sure, I can do that.

Best regards,
Andreas Hindborg

maintainer Applied
#8 lore raw
In reply to Christophe JAILLET
Quoted 11 lines · Christophe JAILLET

These 2 patches constify ct_item_ops and ct_group_ops in struct config_item_type.

When/if they are applied, I'll send some patchess in each subsystem to constify the corresponding structures.

This 2 steps approach is IMHO easier way to make these changes. This avoids long series and cover-letter/first patches sent to many maintainers and lists.

[...]

Applied, thanks!

[1/2] configfs: Constify ct_group_ops in struct config_item_type

      commit: f2f36500a63b73a8be90127322ad740253cf89c0
[2/2] configfs: Constify ct_item_ops in struct config_item_type
      commit: f7f78098690d60a03b47942ac7d73ea17b42239e

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>