driver core: constify groups arrays in few functions and struct class
cover driver core: constify groups arrays in few functions and struct class
This series constifies the attribute group groups arrays in a number of functions, and in struct class. This allows to assign constant arrays, w/o "discards const qualifier" compiler warning.
Heiner Kallweit (3):
sysfs: constify group arrays in function arguments
driver: core: constify groups array argument in device_add_groups and
device_remove_groups
driver core: make struct class groups members constant arrays
drivers/base/core.c | 5 +++-- fs/sysfs/group.c | 10 +++++----- include/linux/device.h | 4 ++-- include/linux/device/class.h | 4 ++-- include/linux/sysfs.h | 16 ++++++++-------- 5 files changed, 20 insertions(+), 19 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/3 sysfs: constify group arrays in function arguments
Constify the groups array argument where applicable. This allows to pass constant arrays as arguments.
--- fs/sysfs/group.c | 10 +++++----- include/linux/sysfs.h | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-)
fs/sysfs/group.c +5 -5
@@ -217,7 +217,7 @@ int sysfs_create_group(struct kobject *kobj,EXPORT_SYMBOL_GPL (sysfs_create_group);static int internal_create_groups (struct kobject *kobj,int update, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {int error =0 ;int i;
@@ -250,7 +250,7 @@ static int internal_create_groups(struct kobject *kobj, int update,* Returns 0 on success or error code from sysfs_create_group on failure. */ int sysfs_create_groups (struct kobject *kobj, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return internal_create_groups (kobj,0 , groups); }
@@ -268,7 +268,7 @@ EXPORT_SYMBOL_GPL(sysfs_create_groups);* Returns 0 on success or error code from sysfs_update_group on failure. */ int sysfs_update_groups (struct kobject *kobj, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return internal_create_groups (kobj,1 , groups); }
@@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(sysfs_remove_group);* If groups is not NULL, remove the specified groups from the kobject. */ void sysfs_remove_groups (struct kobject *kobj, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {int i;
@@ -613,7 +613,7 @@ EXPORT_SYMBOL_GPL(sysfs_group_change_owner);* Returns 0 on success or error code on failure. */ int sysfs_groups_change_owner (struct kobject *kobj, -const struct attribute_group **groups, +const struct attribute_group *const *groups,kuid_t kuid,kgid_t kgid) {int error =0 , i;
include/linux/sysfs.h +8 -8
@@ -445,15 +445,15 @@ void sysfs_delete_link(struct kobject *dir, struct kobject *targ,int __must_check sysfs_create_group (struct kobject *kobj,const struct attribute_group *grp);int __must_check sysfs_create_groups (struct kobject *kobj, -const struct attribute_group **groups); +const struct attribute_group *const *groups);int __must_check sysfs_update_groups (struct kobject *kobj, -const struct attribute_group **groups); +const struct attribute_group *const *groups);int sysfs_update_group (struct kobject *kobj,const struct attribute_group *grp);void sysfs_remove_group (struct kobject *kobj,const struct attribute_group *grp);void sysfs_remove_groups (struct kobject *kobj, -const struct attribute_group **groups); +const struct attribute_group *const *groups);int sysfs_add_file_to_group (struct kobject *kobj,const struct attribute *attr,const char *group); void sysfs_remove_file_from_group(struct kobject *kobj,
@@ -486,7 +486,7 @@ int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid);int sysfs_link_change_owner (struct kobject *kobj,struct kobject *targ,const char *name,kuid_t kuid,kgid_t kgid);int sysfs_groups_change_owner (struct kobject *kobj, -const struct attribute_group **groups, +const struct attribute_group *const *groups,kuid_t kuid,kgid_t kgid); int sysfs_group_change_owner(struct kobject *kobj, const struct attribute_group *groups, kuid_t kuid,
@@ -629,13 +629,13 @@ static inline int sysfs_create_group(struct kobject *kobj, }static inline int sysfs_create_groups (struct kobject *kobj, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return 0 ; }static inline int sysfs_update_groups (struct kobject *kobj, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return 0 ; }
@@ -652,7 +652,7 @@ static inline void sysfs_remove_group(struct kobject *kobj, }static inline void sysfs_remove_groups (struct kobject *kobj, -const struct attribute_group **groups) +const struct attribute_group *const *groups) { }
@@ -733,7 +733,7 @@ static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t k }static inline int sysfs_groups_change_owner (struct kobject *kobj, -const struct attribute_group **groups, +const struct attribute_group *const *groups,kuid_t kuid,kgid_t kgid) {return 0 ;
Signature · 1 line
2.53.0
PATCH 2/3 driver: core: constify groups array argument in device_add_groups and device_remove_groups
In reply to Heiner KallweitNow that sysfs_create_groups() and sysfs_remove_groups() allow to pass constant groups arrays, we can constify the groups array argument also here.
--- drivers/base/core.c | 5 +++-- include/linux/device.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/base/core.c +3 -2
@@ -2831,14 +2831,15 @@ static ssize_t removable_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RO (removable); -int device_add_groups (struct device *dev,const struct attribute_group **groups) +int device_add_groups (struct device *dev, +const struct attribute_group *const *groups) {return sysfs_create_groups (&dev->kobj, groups); }EXPORT_SYMBOL_GPL (device_add_groups);void device_remove_groups (struct device *dev, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {sysfs_remove_groups (&dev->kobj, groups); }
include/linux/device.h +2 -2
@@ -1131,9 +1131,9 @@ device_create_with_groups(const struct class *cls, struct device *parent, dev_tvoid device_destroy (const struct class *cls,dev_t devt);int __must_check device_add_groups (struct device *dev, -const struct attribute_group **groups); +const struct attribute_group *const *groups);void device_remove_groups (struct device *dev, -const struct attribute_group **groups); +const struct attribute_group *const *groups);static inline int __must_check device_add_group (struct device *dev,const struct attribute_group *grp)
Signature · 1 line
2.53.0
PATCH 3/3 driver core: make struct class groups members constant arrays
In reply to Heiner KallweitConstify the groups arrays, allowing to assign constant arrays.
--- include/linux/device/class.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/device/class.h +2 -2
@@ -50,8 +50,8 @@ struct fwnode_handle;struct class {const char *name; -const struct attribute_group **class_groups; -const struct attribute_group **dev_groups; +const struct attribute_group *const *class_groups; +const struct attribute_group *const *dev_groups;int (*dev_uevent)(const struct device *dev,struct kobj_uevent_env *env);char *(*devnode)(const struct device *dev,umode_t *mode);
Signature · 1 line
2.53.0