Re: [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array
From: Heiner Kallweit
Date: Sat Feb 21 2026 - 09:04:36 EST
On 21.02.2026 14:27, Thomas Weißschuh wrote:
> Hello Heiner,
>
> On 2026-02-17 23:32:46+0100, Heiner Kallweit wrote:
>> Constify the default_groups array, allowing to assign constant arrays.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx>
>
> (The patch author/From header and Signed-off-by line do not match)
>
Right, have to fix this once series is out of RFC state.
>> ---
>> include/linux/kobject.h | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/kobject.h b/include/linux/kobject.h
>> index c8219505a79..e45ee843931 100644
>> --- a/include/linux/kobject.h
>> +++ b/include/linux/kobject.h
>> @@ -116,7 +116,7 @@ char *kobject_get_path(const struct kobject *kobj, gfp_t flag);
>> struct kobj_type {
>> void (*release)(struct kobject *kobj);
>> const struct sysfs_ops *sysfs_ops;
>> - const struct attribute_group **default_groups;
>> + const struct attribute_group *const *default_groups;
>
> Thanks for working on this!
>
> Personally I try to constify the attribute structures together with
> their corresponding callbacks. This ensures that no structure is
> constified which its callback then tries to modify.
> Currently there is no support for const arguments to the callbacks of
> 'struct kobj_attribute' and 'struct device_attribute'. I am wondering
> if the changes to kobject and device groups should be kept out for now
> and be added together with the support for their const callback arguments.
>
I think we have to be precise what exactly gets constified:
In the series here it's about arrays of pointers to attribute groups.
Just these arrays can't be modified any longer. This includes no change
to whether data in the attribute groups and attributes can be modified.
These arrays of pointers to attribute groups are used in calls to
sysfs_create_groups() and device_add_groups(), e.g. from create_dir()
for kobject's, and from device_add_attrs().
And sysfs_create_groups() and device_add_groups() are changed accordingly
in this series.
Does this answer your question?
>
> Thomas
>
>> const struct kobj_ns_type_operations *(*child_ns_type)(const struct kobject *kobj);
>> const void *(*namespace)(const struct kobject *kobj);
>> void (*get_ownership)(const struct kobject *kobj, kuid_t *uid, kgid_t *gid);