drivers/rtc/sysfs: move code to count_attribute_groups()
Subsystems (33)
PATCH 1/7 drivers/rtc/sysfs: move code to count_attribute_groups()
This avoids overloading the "groups" variable for three different purposes
--- drivers/rtc/sysfs.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/rtc/sysfs.c +12 -8
@@ -313,21 +313,25 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void)return rtc_attr_groups; } +static size_t count_attribute_groups (const struct attribute_group *const *groups) +{ +size_t count =0 ; + +for (; *groups; ++groups) + ++count; +return count; +} +int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group **grps) { -size_t old_cnt =0 , add_cnt =0 , new_cnt; +size_t old_cnt, add_cnt, new_cnt;const struct attribute_group **groups, **old;if (!grps)return -EINVAL ; - groups = rtc->dev.groups; -if (groups) -for (; *groups; groups++) - old_cnt++; - -for (groups = grps; *groups; groups++) - add_cnt++; + old_cnt = rtc->dev.groups ?count_attribute_groups (rtc->dev.groups) :0 ; + add_cnt =count_attribute_groups (grps); new_cnt = old_cnt + add_cnt +1 ; groups =devm_kcalloc (&rtc->dev, new_cnt,sizeof (*groups),GFP_KERNEL );
Signature · 1 line
2.39.2
PATCH 2/7 drivers/hwmon: add local variable for newly allocated attribute_group**
This allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
--- drivers/hwmon/hwmon.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hwmon/hwmon.c +6 -5
@@ -783,6 +783,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, hdev = &hwdev->dev;if (chip) { +const struct attribute_group **new_groups;struct attribute **attrs;int ngroups =2 ;/* terminating NULL plus &hwdev->groups */
@@ -790,8 +791,8 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,for (i =0 ; groups[i]; i++) ngroups++; - hwdev->groups =kcalloc (ngroups,sizeof (*groups),GFP_KERNEL ); -if (!hwdev->groups) { + hwdev->groups = new_groups =kcalloc (ngroups,sizeof (*new_groups),GFP_KERNEL ); +if (!new_groups) { err = -ENOMEM ; goto free_hwmon; }
@@ -804,14 +805,14 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, hwdev->group.attrs = attrs; ngroups =0 ; - hwdev->groups[ngroups++] = &hwdev->group; + new_groups[ngroups++] = &hwdev->group;if (groups) {for (i =0 ; groups[i]; i++) - hwdev->groups[ngroups++] = groups[i]; + new_groups[ngroups++] = groups[i]; } - hdev->groups = hwdev->groups; + hdev->groups = new_groups; }else { hdev->groups = groups; }
Signature · 1 line
2.39.2
Guenter Roeck
maintainerRe: [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group**
Quoted 4 lines · Max Kellermann
This allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
Signed-off-by Max Kellermann <[email protected]>
I have no idea what this is about, and I don't see how that would improve anything, but ...
Quoted 17 lines
--- drivers/hwmon/hwmon.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/hwmon/hwmon.c +1
-0@@ -783,6 +783,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, hdev = &hwdev->dev;if (chip) { +const struct attribute_group **new_groups;struct attribute **attrs;int ngroups =2 ;/* terminating NULL plus &hwdev->groups */
drivers/hwmon/hwmon.c __hwmon_device_register(struct device *dev, const char *name, void *drvdata, · line 794
Quoted 6 lines
drivers/hwmon/hwmon.c +1
-2@@ -790,8 +791,8 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,for (i =0 ; groups[i]; i++) ngroups++; - hwdev->groups =kcalloc (ngroups,sizeof (*groups),GFP_KERNEL ); -if (!hwdev->groups) { + hwdev->groups = new_groups =kcalloc (ngroups,sizeof (*new_groups),GFP_KERNEL );
CHECK: multiple assignments should be avoided
#101: FILE: drivers/hwmon/hwmon.c:794:
+ hwdev->groups = new_groups = kcalloc(ngroups, sizeof(*new_groups), GFP_KERNEL);
either case, this change is not acceptable.
Guenter
Re: [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group**
Quoted 2 lines · Guenter Roeck
I have no idea what this is about, and I don't see how that would improve anything, but ...
Later, we can make lots of global variables "const", which puts them in ".rodata" (write-protected at runtime). This is some micro-hardening.
Quoted 3 lines
CHECK: multiple assignments should be avoided
#101: FILE:drivers/hwmon/hwmon.c:794:
+hwdev->groups=new_groups=kcalloc(ngroups, sizeof(*new_groups), GFP_KERNEL);
What program emitted this warning? checkpatch.pl had no error. I'll change it in all patches.
Quoted 1 line
either case, this change is not acceptable.
Because of the multi-assignment, or is there something else?
Guenter Roeck
maintainerRe: [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group**
Quoted 8 lines · Max Kellermann
Quoted 2 lines · Guenter Roeck
I have no idea what this is about, and I don't see how that would improve anything, but ...
Later, we can make lots of global variables "const", which puts them in ".rodata" (write-protected at runtime). This is some micro-hardening.
Quoted 6 lines
Quoted 3 lines
CHECK: multiple assignments should be avoided
#101: FILE:drivers/hwmon/hwmon.c:794:
+hwdev->groups=new_groups=kcalloc(ngroups, sizeof(*new_groups), GFP_KERNEL);What program emitted this warning? checkpatch.pl had no error. I'll change it in all patches.
I doubt that you ran checkpatch --strict. That check has existed in checkpatch at least since 2007.
Also, process/coding-style.rst says:
Don't put multiple assignments on a single line either. Kernel coding style is super simple. Avoid tricky expressions.
As far as I know that guildeline has not changed.
Now, you might argue something like "who cares about checkpatch --strict", but in Documentation/hwmon/submitting-patches.rst we specifically say
* Please run your patch through 'checkpatch --strict'. There should be no errors, no warnings, and few if any check messages. If there are any messages, please be prepared to explain.
So, please explain why this message and with it the coding style violation should be ignored.
Quoted 4 lines
Quoted 2 lines
either case, this change is not acceptable.
Because of the multi-assignment, or is there something else?
I don't really see the benefit of this code, and I am not sure if the explanation about compiler optimization is really valid. It makes me want to run some test compliations to see if the claim is really true, and I really don't have time for that.
Also, as Greg points out, this is not in a hot code path but executed exactly once for each hwmon device, so making such a change with a reason like that just invites lots of follow-up patches with similar reasons, and then the submitters of those can point to this patch and argue "but you accepted that one". You say "micro-hardening" above, but for me it is time consuming micro-optimization.
Guenter
Re: [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group**
In reply to Max KellermannQuoted 1 line · Max Kellermann
This allows the compiler to keep the pointer in a register and
Maybe, maybe not, there's no guarantee for register usage.
And it doesn't matter, this is a very slow path, no registers are required :)
Quoted 1 line
prepares for making the struct field "const".
What struct field?
Quoted 19 lines
Signed-off-by Max Kellermann <[email protected]>--- drivers/hwmon/hwmon.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/hwmon/hwmon.c +1
-0@@ -783,6 +783,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, hdev = &hwdev->dev;if (chip) { +const struct attribute_group **new_groups;struct attribute **attrs;int ngroups =2 ;/* terminating NULL plus &hwdev->groups */
drivers/hwmon/hwmon.c __hwmon_device_register(struct device *dev, const char *name, void *drvdata, · line 794
Quoted 6 lines
drivers/hwmon/hwmon.c +1
-2@@ -790,8 +791,8 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,for (i =0 ; groups[i]; i++) ngroups++; - hwdev->groups =kcalloc (ngroups,sizeof (*groups),GFP_KERNEL ); -if (!hwdev->groups) { + hwdev->groups = new_groups =kcalloc (ngroups,sizeof (*new_groups),GFP_KERNEL );
So you have a const pointer AND a non-const pointer pointing to the same thing?
drivers/hwmon/hwmon.c __hwmon_device_register(struct device *dev, const char *name, void *drvdata, · line 808
Quoted 10 lines
drivers/hwmon/hwmon.c +2
-1+if (!new_groups) { err = -ENOMEM ; goto free_hwmon; }@@ -804,14 +805,14 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, hwdev->group.attrs = attrs; ngroups =0 ; - hwdev->groups[ngroups++] = &hwdev->group; + new_groups[ngroups++] = &hwdev->group;
This shoul be identical, you assign both above the same way, so why change this?
drivers/hwmon/hwmon.c __hwmon_device_register(struct device *dev, const char *name, void *drvdata, · line 812
Quoted 5 lines
drivers/hwmon/hwmon.c +1
-1if (groups) {for (i =0 ; groups[i]; i++) - hwdev->groups[ngroups++] = groups[i]; + new_groups[ngroups++] = groups[i];
Same here.
thanks,
greg k-h
Re: [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group**
Quoted 5 lines · Greg KH
Quoted 1 line · Max Kellermann
This allows the compiler to keep the pointer in a register and
Maybe, maybe not, there's no guarantee for register usage.
Agree. But without this change, register usage is effectively prevented (much of the time). With this change, there is a chance for better code. Yeah, it's not a critical code path, and it's only a tiny tiny optimization - but the real reason for this patch is ....
Quoted 6 lines
drivers/hwmon/hwmon.c __hwmon_device_register(struct device *dev, const char *name, void *drvdata, · line 794
Quoted 3 lines
drivers/hwmon/hwmon.c +1
-2- hwdev->groups =kcalloc (ngroups,sizeof (*groups),GFP_KERNEL ); -if (!hwdev->groups) { + hwdev->groups = new_groups =kcalloc (ngroups,sizeof (*new_groups),GFP_KERNEL );So you have a const pointer AND a non-const pointer pointing to the same thing?
.... so I can make "hwdev->groups" const, which wouldn't allow modifying it. (This isn't obvious in this one patch, but a later patch in the series does this.)
There are only few functions which allocate a new pointer-array dynamically; all others are global variables which currently cannot be "const". This patch set does some lifting to allow adding "const".
PATCH 3/7 drivers/extcon: add local variable for newly allocated attribute_group**
In reply to Max KellermannThis allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
--- drivers/extcon/extcon.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/extcon/extcon.c +6 -5
@@ -1202,6 +1202,7 @@ static int extcon_alloc_muex(struct extcon_dev *edev)*/ static int extcon_alloc_groups (struct extcon_dev *edev) { +const struct attribute_group **groups;int index;if (!edev)
@@ -1210,20 +1211,20 @@ static int extcon_alloc_groups(struct extcon_dev *edev)if (!edev->max_supported)return 0 ; - edev->extcon_dev_type.groups =kcalloc (edev->max_supported +2 , -sizeof (*edev->extcon_dev_type.groups), + edev->extcon_dev_type.groups = groups =kcalloc (edev->max_supported +2 , +sizeof (*groups),GFP_KERNEL ); -if (!edev->extcon_dev_type.groups) +if (!groups)return -ENOMEM ; edev->extcon_dev_type.name =dev_name (&edev->dev); edev->extcon_dev_type.release = dummy_sysfs_dev_release;for (index =0 ; index < edev->max_supported; index++) - edev->extcon_dev_type.groups[index] = &edev->cables[index].attr_g; + groups[index] = &edev->cables[index].attr_g;if (edev->mutually_exclusive) - edev->extcon_dev_type.groups[index] = &edev->attr_g_muex; + groups[index] = &edev->attr_g_muex; edev->dev.type = &edev->extcon_dev_type;
Signature · 1 line
2.39.2
Greg KH
maintainerRe: [PATCH 3/7] drivers/extcon: add local variable for newly allocated attribute_group**
Quoted 2 lines · Max Kellermann
This allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
Again, registers have nothing to do with this.
thanks,
greg k-h
PATCH 4/7 drivers/counter: add local variable for newly allocated attribute_group**
In reply to Max KellermannThis allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
--- drivers/counter/counter-sysfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/counter/counter-sysfs.c +4 -3
@@ -1122,6 +1122,7 @@ int counter_sysfs_add(struct counter_device *const counter)struct counter_attribute_group *cattr_groups;size_t i, j;int err; +const struct attribute_group **dev_groups;struct attribute_group *groups;struct counter_attribute *p;
@@ -1141,9 +1142,9 @@ int counter_sysfs_add(struct counter_device *const counter)return err;/* Allocate attribute group pointers for association with device */ - dev->groups =devm_kcalloc (dev, num_groups +1 ,sizeof (*dev->groups), + dev->groups = dev_groups =devm_kcalloc (dev, num_groups +1 ,sizeof (*dev_groups),GFP_KERNEL ); -if (!dev->groups) +if (!dev_groups)return -ENOMEM ;/* Allocate space for attribute groups */
@@ -1169,7 +1170,7 @@ int counter_sysfs_add(struct counter_device *const counter) groups[i].attrs[j++] = &p->dev_attr.attr;/* Associate attribute group */ - dev->groups[i] = &groups[i]; + dev_groups[i] = &groups[i]; }return 0 ;
Signature · 1 line
2.39.2
Greg KH
maintainerRe: [PATCH 4/7] drivers/counter: add local variable for newly allocated attribute_group**
Quoted 2 lines · Max Kellermann
This allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
Again, nothing about registers makes sense here.
thanks,
greg k-h
PATCH 5/7 drivers/tty/serial_core: add local variable for newly allocated attribute_group**
In reply to Max KellermannThis allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
--- drivers/tty/serial/serial_core.c | 11 ++++++----- include/linux/serial_core.h | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/tty/serial/serial_core.c +6 -5
@@ -3082,6 +3082,7 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *ustruct uart_state *state;struct tty_port *port;int ret =0 ; +const struct attribute_group **tty_groups;struct device *tty_dev;int num_groups;
@@ -3132,22 +3133,22 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *uif (uport->attr_group) num_groups++; - uport->tty_groups =kcalloc (num_groups,sizeof (*uport->tty_groups), + uport->tty_groups = tty_groups =kcalloc (num_groups,sizeof (*tty_groups),GFP_KERNEL ); -if (!uport->tty_groups) { +if (!tty_groups) { ret = -ENOMEM ; goto out; } - uport->tty_groups[0 ] = &tty_dev_attr_group; + tty_groups[0 ] = &tty_dev_attr_group;if (uport->attr_group) - uport->tty_groups[1 ] = uport->attr_group; + tty_groups[1 ] = uport->attr_group;/* * Register the port whether it's detected or not. This allows * setserial to be used to alter this port's parameters. */ tty_dev =tty_port_register_device_attr_serdev (port, drv->tty_driver, - uport->line, uport->dev, port, uport->tty_groups); + uport->line, uport->dev, port, tty_groups);if (!IS_ERR (tty_dev)) {device_set_wakeup_capable (tty_dev,1 ); }else {
include/linux/serial_core.h +2 -2
@@ -578,8 +578,8 @@ struct uart_port {unsigned char suspended;unsigned char console_reinit;const char *name;/* port name */ -struct attribute_group *attr_group;/* port specific attributes */ -const struct attribute_group **tty_groups;/* all attributes (serial core use only) */ +const struct attribute_group *attr_group;/* port specific attributes */ +const struct attribute_group *const *tty_groups;/* all attributes (serial core use only) */ struct serial_rs485 rs485;struct serial_rs485 rs485_supported;/* Supported mask for serial_rs485 */ struct gpio_desc *rs485_term_gpio;/* enable RS485 bus termination */
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerRe: [PATCH 5/7] drivers/tty/serial_core: add local variable for newly allocated attribute_group**
Quoted 2 lines · Max Kellermann
This allows the compiler to keep the pointer in a register and prepares for making the struct field "const".
You know what I'm going to say...
PATCH 6/7 fs/sysfs/group: make attribute_group pointers const
In reply to Max KellermannThis allows passing arrays of const pointers. The goal is to make lots of global variables "const" to allow them to live in the ".rodata" section.
--- block/genhd.c | 2 +- drivers/base/base.h | 4 ++-- drivers/base/bus.c | 6 +++--- drivers/base/cacheinfo.c | 4 ++-- drivers/base/core.c | 14 +++++++------- drivers/base/cpu.c | 4 ++-- drivers/base/driver.c | 4 ++-- drivers/edac/edac_mc.c | 2 +- drivers/edac/edac_mc.h | 2 +- drivers/edac/edac_mc_sysfs.c | 2 +- drivers/edac/edac_module.h | 2 +- drivers/hwmon/hwmon.c | 12 ++++++------ drivers/hwmon/pmbus/pmbus.h | 2 +- drivers/infiniband/core/core_priv.h | 4 ++-- drivers/infiniband/core/sysfs.c | 4 ++-- drivers/infiniband/ulp/srp/ib_srp.c | 2 +- drivers/iommu/iommu-sysfs.c | 2 +- drivers/nvdimm/dimm_devs.c | 2 +- drivers/nvme/host/nvme.h | 2 +- drivers/rtc/rtc-core.h | 4 ++-- drivers/rtc/sysfs.c | 6 +++--- drivers/tty/tty_io.c | 2 +- drivers/tty/tty_port.c | 4 ++-- fs/sysfs/group.c | 10 +++++----- include/linux/blkdev.h | 2 +- include/linux/coresight.h | 2 +- include/linux/cpu.h | 2 +- include/linux/device.h | 16 ++++++++-------- include/linux/device/bus.h | 6 +++--- include/linux/device/class.h | 4 ++-- include/linux/device/driver.h | 4 ++-- include/linux/hwmon.h | 8 ++++---- include/linux/iommu.h | 4 ++-- include/linux/kobject.h | 2 +- include/linux/leds.h | 4 ++-- include/linux/libnvdimm.h | 8 ++++---- include/linux/miscdevice.h | 2 +- include/linux/pci.h | 4 ++-- include/linux/perf_event.h | 2 +- include/linux/power_supply.h | 2 +- include/linux/rtc.h | 4 ++-- include/linux/sysfs.h | 16 ++++++++-------- include/linux/tty_driver.h | 2 +- include/linux/tty_port.h | 4 ++-- include/linux/usb.h | 4 ++-- include/linux/w1.h | 2 +- include/linux/watchdog.h | 2 +- include/rdma/ib_verbs.h | 2 +- include/scsi/scsi_host.h | 4 ++-- 49 files changed, 107 insertions(+), 107 deletions(-)
block/genhd.c +1 -1
@@ -394,7 +394,7 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)* with the kernel. */ int __must_check device_add_disk (struct device *parent,struct gendisk *disk, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {struct device *ddev =disk_to_dev (disk);
drivers/base/base.h +2 -2
@@ -175,8 +175,8 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); } -int driver_add_groups (struct device_driver *drv,const struct attribute_group **groups); -void driver_remove_groups (struct device_driver *drv,const struct attribute_group **groups); +int driver_add_groups (struct device_driver *drv,const struct attribute_group *const *groups); +void driver_remove_groups (struct device_driver *drv,const struct attribute_group *const *groups);void device_driver_detach (struct device *dev);int devres_release_all (struct device *dev);
drivers/base/bus.c +3 -3
@@ -1195,7 +1195,7 @@ static void system_root_device_release(struct device *dev) }static int subsys_register (struct bus_type *subsys, -const struct attribute_group **groups, +const struct attribute_group *const *groups,struct kobject *parent_of_root) {struct subsys_private *sp;
@@ -1265,7 +1265,7 @@ static int subsys_register(struct bus_type *subsys,* /sys/devices/system/<name>. */ int subsys_system_register (struct bus_type *subsys, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return subsys_register (subsys, groups, &system_kset->kobj); }
@@ -1283,7 +1283,7 @@ EXPORT_SYMBOL_GPL(subsys_system_register);* constructs which need sysfs interface. */ int subsys_virtual_register (struct bus_type *subsys, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {struct kobject *virtual_dir;
drivers/base/cacheinfo.c +2 -2
@@ -803,7 +803,7 @@ __weak cache_get_priv_group(struct cacheinfo *this_leaf)return NULL ; } -static const struct attribute_group ** +static const struct attribute_group *const *cache_get_attribute_groups (struct cacheinfo *this_leaf) { const struct attribute_group *priv_group =
@@ -868,7 +868,7 @@ static int cache_add_dev(unsigned int cpu)int rc;struct device *ci_dev, *parent;struct cacheinfo *this_leaf; -const struct attribute_group **cache_groups; +const struct attribute_group *const *cache_groups; rc =cpu_cache_sysfs_init (cpu);if (unlikely (rc <0 ))
drivers/base/core.c +7 -7
@@ -2721,14 +2721,14 @@ 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); }
@@ -2736,7 +2736,7 @@ EXPORT_SYMBOL_GPL(device_remove_groups);union device_attr_group_devres {const struct attribute_group *group; -const struct attribute_group **groups; +const struct attribute_group *const *groups; };static void devm_attr_group_remove (struct device *dev,void *res)
@@ -2751,7 +2751,7 @@ static void devm_attr_group_remove(struct device *dev, void *res)static void devm_attr_groups_remove (struct device *dev,void *res) {union device_attr_group_devres *devres = res; -const struct attribute_group **groups = devres->groups; +const struct attribute_group *const *groups = devres->groups;dev_dbg (dev,"%s: removing groups %p\n" , __func__, groups);sysfs_remove_groups (&dev->kobj, groups);
@@ -2803,7 +2803,7 @@ EXPORT_SYMBOL_GPL(devm_device_add_group);* Returns 0 on success or error code from sysfs_create_group on failure. */ int devm_device_add_groups (struct device *dev, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {union device_attr_group_devres *devres;int error;
@@ -4281,7 +4281,7 @@ static void device_create_release(struct device *dev) static __printf(6, 0) struct device * device_create_groups_vargs(const struct class *class, struct device *parent, dev_t devt, void *drvdata, - const struct attribute_group **groups, + const struct attribute_group *const*groups, const char *fmt, va_list args) { struct device *dev = NULL;
@@ -4381,7 +4381,7 @@ EXPORT_SYMBOL_GPL(device_create);struct device *device_create_with_groups (const struct class *class,struct device *parent,dev_t devt,void *drvdata, -const struct attribute_group **groups, +const struct attribute_group *const *groups,const char *fmt, ...) {va_list vargs;
drivers/base/cpu.c +2 -2
@@ -434,7 +434,7 @@ static void device_create_release(struct device *dev) __printf(4, 0)static struct device *__cpu_device_create (struct device *parent,void *drvdata, -const struct attribute_group **groups, +const struct attribute_group *const *groups,const char *fmt,va_list args) {struct device *dev =NULL ;
@@ -467,7 +467,7 @@ __cpu_device_create(struct device *parent, void *drvdata, }struct device *cpu_device_create (struct device *parent,void *drvdata, -const struct attribute_group **groups, +const struct attribute_group *const *groups,const char *fmt, ...) {va_list vargs;
drivers/base/driver.c +2 -2
@@ -200,13 +200,13 @@ void driver_remove_file(struct device_driver *drv,EXPORT_SYMBOL_GPL (driver_remove_file);int driver_add_groups (struct device_driver *drv, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return sysfs_create_groups (&drv->p->kobj, groups); }void driver_remove_groups (struct device_driver *drv, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {sysfs_remove_groups (&drv->p->kobj, groups); }
drivers/edac/edac_mc.c +1 -1
@@ -598,7 +598,7 @@ EXPORT_SYMBOL_GPL(edac_get_owner);/* FIXME - should a warning be printed if no error detection? correction? */ int edac_mc_add_mc_with_groups (struct mem_ctl_info *mci, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {int ret = -EINVAL ;edac_dbg (0 ,"\n" );
drivers/edac/edac_mc.h +1 -1
@@ -146,7 +146,7 @@ extern const char *edac_get_owner(void);* 0 on Success, or an error code on failure */ extern int edac_mc_add_mc_with_groups (struct mem_ctl_info *mci, -const struct attribute_group **groups); +const struct attribute_group *const *groups);#define edac_mc_add_mc (mci) edac_mc_add_mc_with_groups(mci, NULL)/**
drivers/edac/edac_mc_sysfs.c +1 -1
@@ -931,7 +931,7 @@ static const struct device_type mci_attr_type = {* !0 Failure */ int edac_create_sysfs_mci_device (struct mem_ctl_info *mci, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {struct dimm_info *dimm;int err;
drivers/edac/edac_module.h +1 -1
@@ -27,7 +27,7 @@int edac_mc_sysfs_init (void );void edac_mc_sysfs_exit (void );extern int edac_create_sysfs_mci_device (struct mem_ctl_info *mci, -const struct attribute_group **groups); +const struct attribute_group *const *groups);extern void edac_remove_sysfs_mci_device (struct mem_ctl_info *mci);extern int edac_mc_get_log_ue (void );extern int edac_mc_get_log_ce (void );
drivers/hwmon/hwmon.c +6 -6
@@ -37,7 +37,7 @@ struct hwmon_device {const struct hwmon_chip_info *chip;struct list_head tzdata;struct attribute_group group; -const struct attribute_group **groups; +const struct attribute_group *const *groups; };#define to_hwmon_device (d) container_of(d, struct hwmon_device, dev)
@@ -756,7 +756,7 @@ __hwmon_create_attrs(const void *drvdata, const struct hwmon_chip_info *chip)static struct device *__hwmon_device_register (struct device *dev,const char *name,void *drvdata,const struct hwmon_chip_info *chip, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {struct hwmon_device *hwdev;const char *label;
@@ -884,7 +884,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,struct device *hwmon_device_register_with_groups (struct device *dev,const char *name,void *drvdata, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {if (!name)return ERR_PTR (-EINVAL );
@@ -911,7 +911,7 @@ struct device * hwmon_device_register_with_info(struct device *dev, const char *name, void *drvdata, const struct hwmon_chip_info *chip, - const struct attribute_group **extra_groups) + const struct attribute_group *const*extra_groups) { if (!dev || !name || !chip) return ERR_PTR(-EINVAL);
@@ -1004,7 +1004,7 @@ static void devm_hwmon_release(struct device *dev, void *res)struct device *devm_hwmon_device_register_with_groups (struct device *dev,const char *name,void *drvdata, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {struct device **ptr, *hwdev;
@@ -1044,7 +1044,7 @@ struct device * devm_hwmon_device_register_with_info(struct device *dev, const char *name, void *drvdata, const struct hwmon_chip_info *chip, - const struct attribute_group **extra_groups) + const struct attribute_group *const*extra_groups) { struct device **ptr, *hwdev;
drivers/hwmon/pmbus/pmbus.h +1 -1
@@ -456,7 +456,7 @@ struct pmbus_driver_info {const struct regulator_desc *reg_desc;/* custom attributes */ -const struct attribute_group **groups; +const struct attribute_group *const *groups; };/* Regulator ops */
drivers/infiniband/core/core_priv.h +2 -2
@@ -351,9 +351,9 @@ int ib_setup_device_attrs(struct ib_device *ibdev);int rdma_compatdev_set (u8 enable);int ib_port_register_client_groups (struct ib_device *ibdev,u32 port_num, -const struct attribute_group **groups); +const struct attribute_group *const *groups);void ib_port_unregister_client_groups (struct ib_device *ibdev,u32 port_num, -const struct attribute_group **groups); +const struct attribute_group *const *groups);int ib_device_set_netns_put (struct sk_buff *skb,struct ib_device *dev,u32 ns_fd);
drivers/infiniband/core/sysfs.c +2 -2
@@ -1464,7 +1464,7 @@ int ib_setup_port_attrs(struct ib_core_device *coredev)* Do not use. Only for legacy sysfs compatibility. */ int ib_port_register_client_groups (struct ib_device *ibdev,u32 port_num, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return sysfs_create_groups (&ibdev->port_data[port_num].sysfs->kobj, groups);
@@ -1472,7 +1472,7 @@ int ib_port_register_client_groups(struct ib_device *ibdev, u32 port_num,EXPORT_SYMBOL (ib_port_register_client_groups);void ib_port_unregister_client_groups (struct ib_device *ibdev,u32 port_num, -const struct attribute_group **groups) +const struct attribute_group *const *groups) {return sysfs_remove_groups (&ibdev->port_data[port_num].sysfs->kobj, groups);
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
@@ -1021,7 +1021,7 @@ static int srp_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd)*/ static void srp_del_scsi_host_attr (struct Scsi_Host *shost) { -const struct attribute_group **g; +const struct attribute_group *const *g;struct attribute **attr;for (g = shost->hostt->shost_groups; *g; ++g) {
drivers/iommu/iommu-sysfs.c +1 -1
@@ -53,7 +53,7 @@ postcore_initcall(iommu_dev_init);*/ int iommu_device_sysfs_add (struct iommu_device *iommu,struct device *parent, -const struct attribute_group **groups, +const struct attribute_group *const *groups,const char *fmt, ...) {va_list vargs;
drivers/nvdimm/dimm_devs.c +1 -1
@@ -580,7 +580,7 @@ bool is_nvdimm(const struct device *dev)static struct lock_class_key nvdimm_key; struct nvdimm *__nvdimm_create(struct nvdimm_bus *nvdimm_bus, - void *provider_data, const struct attribute_group **groups, + void *provider_data, const struct attribute_group *const*groups, unsigned long flags, unsigned long cmd_mask, int num_flush, struct resource *flush_wpq, const char *dimm_id, const struct nvdimm_security_ops *sec_ops,
drivers/nvme/host/nvme.h +1 -1
@@ -524,7 +524,7 @@ struct nvme_ctrl_ops {#define NVME_F_METADATA_SUPPORTED (1 << 1)#define NVME_F_BLOCKING (1 << 2) -const struct attribute_group **dev_attr_groups; +const struct attribute_group *const *dev_attr_groups;int (*reg_read32)(struct nvme_ctrl *ctrl,u32 off,u32 *val);int (*reg_write32)(struct nvme_ctrl *ctrl,u32 off,u32 val);int (*reg_read64)(struct nvme_ctrl *ctrl,u32 off,u64 *val);
drivers/rtc/rtc-core.h +2 -2
@@ -34,9 +34,9 @@ static inline void rtc_proc_del_device(struct rtc_device *rtc)#endif #ifdef CONFIG_RTC_INTF_SYSFS -const struct attribute_group **rtc_get_dev_attribute_groups (void ); +const struct attribute_group *const *rtc_get_dev_attribute_groups (void );#else -static inline const struct attribute_group **rtc_get_dev_attribute_groups (void ) +static inline const struct attribute_group *const *rtc_get_dev_attribute_groups (void ) {return NULL ; }
drivers/rtc/sysfs.c +3 -3
@@ -308,7 +308,7 @@ static const struct attribute_group *rtc_attr_groups[] = { NULL }; -const struct attribute_group **rtc_get_dev_attribute_groups (void ) +const struct attribute_group *const *rtc_get_dev_attribute_groups (void ) {return rtc_attr_groups; }
@@ -322,10 +322,10 @@ static size_t count_attribute_groups(const struct attribute_group *const*groups)return count; } -int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group **grps) +int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group *const *grps) {size_t old_cnt, add_cnt, new_cnt; -const struct attribute_group **groups, **old; +const struct attribute_group **groups, *const *old;if (!grps)return -EINVAL ;
drivers/tty/tty_io.c +1 -1
@@ -3212,7 +3212,7 @@ static void tty_device_create_release(struct device *dev)struct device *tty_register_device_attr (struct tty_driver *driver,unsigned index,struct device *device,void *drvdata, -const struct attribute_group **attr_grp) +const struct attribute_group *const *attr_grp) {char name[64 ];dev_t devt =MKDEV (driver->major, driver->minor_start) + index;
drivers/tty/tty_port.c +2 -2
@@ -158,7 +158,7 @@ EXPORT_SYMBOL_GPL(tty_port_register_device);struct device *tty_port_register_device_attr (struct tty_port *port,struct tty_driver *driver,unsigned index,struct device *device,void *drvdata, -const struct attribute_group **attr_grp) +const struct attribute_group *const *attr_grp) {tty_port_link_device (port, driver, index); return tty_register_device_attr(driver, index, device, drvdata,
@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(tty_port_register_device_attr);struct device *tty_port_register_device_attr_serdev (struct tty_port *port,struct tty_driver *driver,unsigned index,struct device *device,void *drvdata, -const struct attribute_group **attr_grp) +const struct attribute_group *const *attr_grp) {struct device *dev;
fs/sysfs/group.c +5 -5
@@ -180,7 +180,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;
@@ -213,7 +213,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); }
@@ -231,7 +231,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); }
@@ -306,7 +306,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;
@@ -561,7 +561,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/blkdev.h +1 -1
@@ -729,7 +729,7 @@ static inline unsigned int blk_queue_depth(struct request_queue *q)for (; _bio; _bio = _bio->bi_next) int __must_check device_add_disk(struct device *parent, struct gendisk *disk, - const struct attribute_group **groups); + const struct attribute_group *const*groups);static inline int __must_check add_disk (struct gendisk *disk) {return device_add_disk (NULL , disk,NULL );
include/linux/coresight.h +1 -1
@@ -157,7 +157,7 @@ struct coresight_desc {const struct coresight_ops *ops;struct coresight_platform_data *pdata;struct device *dev; -const struct attribute_group **groups; +const struct attribute_group *const *groups;const char *name;struct csdev_access access; };
include/linux/cpu.h +1 -1
@@ -78,7 +78,7 @@ extern ssize_t cpu_show_gds(struct device *dev, extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata, - const struct attribute_group **groups, + const struct attribute_group *const*groups, const char *fmt, ...); #ifdef CONFIG_HOTPLUG_CPU extern void unregister_cpu(struct cpu *cpu);
include/linux/device.h +8 -8
@@ -73,9 +73,9 @@ int subsys_interface_register(struct subsys_interface *sif);void subsys_interface_unregister (struct subsys_interface *sif);int subsys_system_register (struct bus_type *subsys, -const struct attribute_group **groups); +const struct attribute_group *const *groups);int subsys_virtual_register (struct bus_type *subsys, -const struct attribute_group **groups); +const struct attribute_group *const *groups);/* * The type of device, "struct device" is embedded in. A class
@@ -88,7 +88,7 @@ int subsys_virtual_register(struct bus_type *subsys,*/ struct device_type {const char *name; -const struct attribute_group **groups; +const struct attribute_group *const *groups;int (*uevent)(const struct device *dev,struct kobj_uevent_env *env);char *(*devnode)(const struct device *dev,umode_t *mode,kuid_t *uid,kgid_t *gid);
@@ -782,7 +782,7 @@ struct device {struct list_head devres_head;const struct class *class; -const struct attribute_group **groups;/* optional groups */ +const struct attribute_group *const *groups;/* optional groups */ void (*release)(struct device *dev);struct iommu_group *iommu_group;
@@ -1177,14 +1177,14 @@ device_create(const struct class *cls, struct device *parent, dev_t devt, void *drvdata, const char *fmt, ...); __printf(6, 7) struct device *device_create_with_groups (const struct class *cls,struct device *parent,dev_t devt, -void *drvdata,const struct attribute_group **groups, +void *drvdata,const struct attribute_group *const *groups,const char *fmt, ...);void 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)
@@ -1203,7 +1203,7 @@ static inline void device_remove_group(struct device *dev, }int __must_check devm_device_add_groups (struct device *dev, -const struct attribute_group **groups); +const struct attribute_group *const *groups);int __must_check devm_device_add_group (struct device *dev,const struct attribute_group *grp);
include/linux/device/bus.h +3 -3
@@ -80,9 +80,9 @@ struct fwnode_handle;struct bus_type {const char *name;const char *dev_name; -const struct attribute_group **bus_groups; -const struct attribute_group **dev_groups; -const struct attribute_group **drv_groups; +const struct attribute_group *const *bus_groups; +const struct attribute_group *const *dev_groups; +const struct attribute_group *const *drv_groups;int (*match)(struct device *dev,struct device_driver *drv);int (*uevent)(const struct device *dev,struct kobj_uevent_env *env);
include/linux/device/class.h +2 -2
@@ -52,8 +52,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);
include/linux/device/driver.h +2 -2
@@ -112,8 +112,8 @@ struct device_driver {void (*shutdown) (struct device *dev);int (*suspend) (struct device *dev,pm_message_t state);int (*resume) (struct device *dev); -const struct attribute_group **groups; -const struct attribute_group **dev_groups; +const struct attribute_group *const *groups; +const struct attribute_group *const *dev_groups;const struct dev_pm_ops *pm;void (*coredump) (struct device *dev);
include/linux/hwmon.h +4 -4
@@ -453,16 +453,16 @@ struct device *hwmon_device_register(struct device *dev);struct device *hwmon_device_register_with_groups (struct device *dev,const char *name,void *drvdata, -const struct attribute_group **groups); +const struct attribute_group *const *groups);struct device *devm_hwmon_device_register_with_groups (struct device *dev,const char *name,void *drvdata, -const struct attribute_group **groups); +const struct attribute_group *const *groups);struct device *hwmon_device_register_with_info (struct device *dev,const char *name,void *drvdata,const struct hwmon_chip_info *info, -const struct attribute_group **extra_groups); +const struct attribute_group *const *extra_groups);struct device *hwmon_device_register_for_thermal (struct device *dev,const char *name,void *drvdata);
@@ -470,7 +470,7 @@ struct device * devm_hwmon_device_register_with_info(struct device *dev, const char *name, void *drvdata, const struct hwmon_chip_info *info, - const struct attribute_group **extra_groups); + const struct attribute_group *const*extra_groups);void hwmon_device_unregister (struct device *dev);void devm_hwmon_device_unregister (struct device *dev);
include/linux/iommu.h +2 -2
@@ -441,7 +441,7 @@ int iommu_device_register(struct iommu_device *iommu,void iommu_device_unregister (struct iommu_device *iommu); int iommu_device_sysfs_add(struct iommu_device *iommu, struct device *parent, - const struct attribute_group **groups, + const struct attribute_group *const*groups, const char *fmt, ...) __printf(4, 5);void iommu_device_sysfs_remove (struct iommu_device *iommu);int iommu_device_link (struct iommu_device *iommu,struct device *link);
@@ -975,7 +975,7 @@ static inline void iommu_device_unregister(struct iommu_device *iommu)static inline int iommu_device_sysfs_add (struct iommu_device *iommu,struct device *parent, -const struct attribute_group **groups, +const struct attribute_group *const *groups,const char *fmt, ...) {return -ENODEV ;
include/linux/kobject.h +1 -1
@@ -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;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);
include/linux/leds.h +2 -2
@@ -166,7 +166,7 @@ struct led_classdev {int (*pattern_clear)(struct led_classdev *led_cdev);struct device *dev; -const struct attribute_group **groups; +const struct attribute_group *const *groups;struct list_head node;/* LED Device list */ const char *default_trigger;/* Trigger to use */
@@ -484,7 +484,7 @@ struct led_trigger {/* Link to next registered trigger */ struct list_head next_trig; -const struct attribute_group **groups; +const struct attribute_group *const *groups; };/*
include/linux/libnvdimm.h +4 -4
@@ -82,7 +82,7 @@ typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc,struct device_node ;struct nvdimm_bus_descriptor { -const struct attribute_group **attr_groups; +const struct attribute_group *const *attr_groups;unsigned long cmd_mask;unsigned long dimm_family_mask;unsigned long bus_family_mask;
@@ -126,7 +126,7 @@ struct nd_region_desc {struct resource *res;struct nd_mapping_desc *mapping;u16 num_mappings; -const struct attribute_group **attr_groups; +const struct attribute_group *const *attr_groups;struct nd_interleave_set *nd_set;void *provider_data;int num_lanes;
@@ -259,13 +259,13 @@ struct kobject *nvdimm_kobj(struct nvdimm *nvdimm);unsigned long nvdimm_cmd_mask (struct nvdimm *nvdimm);void *nvdimm_provider_data (struct nvdimm *nvdimm);struct nvdimm *__nvdimm_create (struct nvdimm_bus *nvdimm_bus, -void *provider_data,const struct attribute_group **groups, +void *provider_data,const struct attribute_group *const *groups,unsigned long flags,unsigned long cmd_mask,int num_flush,struct resource *flush_wpq,const char *dimm_id,const struct nvdimm_security_ops *sec_ops,const struct nvdimm_fw_ops *fw_ops);static inline struct nvdimm *nvdimm_create (struct nvdimm_bus *nvdimm_bus, -void *provider_data,const struct attribute_group **groups, +void *provider_data,const struct attribute_group *const *groups,unsigned long flags,unsigned long cmd_mask,int num_flush,struct resource *flush_wpq) {
include/linux/miscdevice.h +1 -1
@@ -83,7 +83,7 @@ struct miscdevice {struct list_head list;struct device *parent;struct device *this_device; -const struct attribute_group **groups; +const struct attribute_group *const *groups;const char *nodename;umode_t mode; };
include/linux/pci.h +2 -2
@@ -928,8 +928,8 @@ struct pci_driver {int (*sriov_set_msix_vec_count)(struct pci_dev *vf,int msix_vec_count);/* On PF */ u32 (*sriov_get_vf_total_msix)(struct pci_dev *pf);const struct pci_error_handlers *err_handler; -const struct attribute_group **groups; -const struct attribute_group **dev_groups; +const struct attribute_group *const *groups; +const struct attribute_group *const *dev_groups;struct device_driver driver;struct pci_dynids dynids;bool driver_managed_dma;
include/linux/perf_event.h +1 -1
@@ -306,7 +306,7 @@ struct pmu {struct device *dev;struct device *parent;const struct attribute_group **attr_groups; -const struct attribute_group **attr_update; +const struct attribute_group *const *attr_update;const char *name;int type;
include/linux/power_supply.h +1 -1
@@ -232,7 +232,7 @@ struct power_supply_config {void *drv_data;/* Device specific sysfs attributes */ -const struct attribute_group **attr_grp; +const struct attribute_group *const *attr_grp;char **supplied_to;size_t num_supplicants;
include/linux/rtc.h +2 -2
@@ -247,7 +247,7 @@ static inline int devm_rtc_nvmem_register(struct rtc_device *rtc,#ifdef CONFIG_RTC_INTF_SYSFS int rtc_add_group (struct rtc_device *rtc,const struct attribute_group *grp); -int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group **grps); +int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group *const *grps);#else static inline int rtc_add_group (struct rtc_device *rtc,const struct attribute_group *grp)
@@ -256,7 +256,7 @@ int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp) }static inline -int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group **grps) +int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group *const *grps) {return 0 ; }
include/linux/sysfs.h +8 -8
@@ -307,15 +307,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,
@@ -348,7 +348,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,
@@ -487,13 +487,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 ; }
@@ -510,7 +510,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) { }
@@ -591,7 +591,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 ;
include/linux/tty_driver.h +1 -1
@@ -571,7 +571,7 @@ struct device *tty_register_device(struct tty_driver *driver, unsigned index, struct device *dev);struct device *tty_register_device_attr (struct tty_driver *driver,unsigned index,struct device *device,void *drvdata, -const struct attribute_group **attr_grp); +const struct attribute_group *const *attr_grp);void tty_unregister_device (struct tty_driver *driver,unsigned index);#ifdef CONFIG_PROC_FS
include/linux/tty_port.h +2 -2
@@ -146,14 +146,14 @@ struct device *tty_port_register_device(struct tty_port *port,struct device *tty_port_register_device_attr (struct tty_port *port,struct tty_driver *driver,unsigned index,struct device *device,void *drvdata, -const struct attribute_group **attr_grp); +const struct attribute_group *const *attr_grp);struct device *tty_port_register_device_serdev (struct tty_port *port,struct tty_driver *driver,unsigned index,struct device *device);struct device *tty_port_register_device_attr_serdev (struct tty_port *port,struct tty_driver *driver,unsigned index,struct device *device,void *drvdata, -const struct attribute_group **attr_grp); +const struct attribute_group *const *attr_grp);void tty_port_unregister_device (struct tty_port *port,struct tty_driver *driver,unsigned index);int tty_port_alloc_xmit_buf (struct tty_port *port);
include/linux/usb.h +2 -2
@@ -1239,7 +1239,7 @@ struct usb_driver {int (*post_reset)(struct usb_interface *intf);const struct usb_device_id *id_table; -const struct attribute_group **dev_groups; +const struct attribute_group *const *dev_groups;struct usb_dynids dynids;struct usbdrv_wrap drvwrap;
@@ -1287,7 +1287,7 @@ struct usb_device_driver {int (*suspend) (struct usb_device *udev,pm_message_t message);int (*resume) (struct usb_device *udev,pm_message_t message); -const struct attribute_group **dev_groups; +const struct attribute_group *const *dev_groups;struct usbdrv_wrap drvwrap;const struct usb_device_id *id_table; unsigned int supports_autosuspend:1;
include/linux/w1.h +1 -1
@@ -253,7 +253,7 @@ void w1_remove_master_device(struct w1_bus_master *master);struct w1_family_ops {int (*add_slave)(struct w1_slave *sl);void (*remove_slave)(struct w1_slave *sl); -const struct attribute_group **groups; +const struct attribute_group *const *groups;const struct hwmon_chip_info *chip_info; };
include/linux/watchdog.h +1 -1
@@ -94,7 +94,7 @@ struct watchdog_ops {struct watchdog_device {int id;struct device *parent; -const struct attribute_group **groups; +const struct attribute_group *const *groups;const struct watchdog_info *info;const struct watchdog_ops *ops;const struct watchdog_governor *gov;
include/rdma/ib_verbs.h +1 -1
@@ -2343,7 +2343,7 @@ struct ib_device_ops {* mechanism exists only for existing drivers. */ const struct attribute_group *device_group; -const struct attribute_group **port_groups; +const struct attribute_group *const *port_groups;int (*post_send)(struct ib_qp *qp,const struct ib_send_wr *send_wr,const struct ib_send_wr **bad_send_wr);
include/scsi/scsi_host.h +2 -2
@@ -478,13 +478,13 @@ struct scsi_host_template {/* * Pointer to the SCSI host sysfs attribute groups, NULL terminated. */ -const struct attribute_group **shost_groups; +const struct attribute_group *const *shost_groups;/* * Pointer to the SCSI device attribute groups for this host, * NULL terminated. */ -const struct attribute_group **sdev_groups; +const struct attribute_group *const *sdev_groups;/* * Vendor Identifier associated with the host
Signature · 1 line
2.39.2
Guenter Roeck
maintainerRe: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
Quoted 5 lines · Max Kellermann
This allows passing arrays of const pointers. The goal is to make lots of global variables "const" to allow them to live in the ".rodata" section.
Signed-off-by Max Kellermann <[email protected]>
In my opinion this touches way too many subsystems in a single patch. If someting is wrong with just one of the changes, it will be all but impossible to revert the whole thing.
Also, I don't know why checkpatch is happy with all the
const struct attribute_group *const*groups;
instead of
const struct attribute_group *const *groups;
but I still don't like it.
Guenter
Re: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
Quoted 7 lines · Guenter Roeck
Also, I don't know why checkpatch is happy with all the
const struct attribute_group *const*groups;instead of
const struct attribute_group *const *groups;
I found out that checkpatch has no check for this at all; it does complain about such lines, but only for local variables. But that warning is actually a bug, because this is a check for unary
operators: it thinks the asterisk is a dereference operator, not a pointer declaration, and complains that the unary operator must be preceded by a space. Thus warnings on local variable are only correct by coincidence, not by design.
Inside structs or parameters (where my coding style violations can be found), it's a different context and thus checkpatch doesn't apply the rules for unary operators.
Greg Kroah-Hartman
maintainerRe: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
Quoted 17 lines · Max Kellermann
Quoted 7 lines · Guenter Roeck
Also, I don't know why checkpatch is happy with all the
const struct attribute_group *const*groups;instead of
const struct attribute_group *const *groups;I found out that checkpatch has no check for this at all; it does complain about such lines, but only for local variables. But that warning is actually a bug, because this is a check for unary
operators: it thinks the asterisk is a dereference operator, not a pointer declaration, and complains that the unary operator must be preceded by a space. Thus warnings on local variable are only correct by coincidence, not by design.
Quoted 3 lines
Inside structs or parameters (where my coding style violations can be found), it's a different context and thus checkpatch doesn't apply the rules for unary operators.
Ok, checkpatch support isn't always required, we can notice that changes like this obviously are not sane and shouldn't be allowed just by reading them :)
thanks,
greg k-h
Re: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
In reply to Max KellermannQuoted 17 lines · Max Kellermann
Quoted 7 lines · Guenter Roeck
Also, I don't know why checkpatch is happy with all the
const struct attribute_group *const*groups;instead of
const struct attribute_group *const *groups;I found out that checkpatch has no check for this at all; it does complain about such lines, but only for local variables. But that warning is actually a bug, because this is a check for unary
operators: it thinks the asterisk is a dereference operator, not a pointer declaration, and complains that the unary operator must be preceded by a space. Thus warnings on local variable are only correct by coincidence, not by design.
Quoted 3 lines
Inside structs or parameters (where my coding style violations can be found), it's a different context and thus checkpatch doesn't apply the rules for unary operators.
My opinion is that const use in the kernel should almost always have whitespace before and after it except when preceded by a open parenthesis or a newline.
$ git grep -wh const -- '*.[ch]' | \
grep -oP "[ \*\(]?const[ \*]?" | \
sort | uniq -c | sort -rn
222438 const
83386 const
51667 (const
2766 *const
834 const
442 const
343 const*
88 *const
37 (const
4 *const*Greg Kroah-Hartman
maintainerRe: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
Quoted 18 lines · Joe Perches
Quoted 17 lines · Max Kellermann
Quoted 7 lines · Guenter Roeck
Also, I don't know why checkpatch is happy with all the
const struct attribute_group *const*groups;instead of
const struct attribute_group *const *groups;I found out that checkpatch has no check for this at all; it does complain about such lines, but only for local variables. But that warning is actually a bug, because this is a check for unary
operators: it thinks the asterisk is a dereference operator, not a pointer declaration, and complains that the unary operator must be preceded by a space. Thus warnings on local variable are only correct by coincidence, not by design.
Quoted 7 lines
Quoted 3 lines
Inside structs or parameters (where my coding style violations can be found), it's a different context and thus checkpatch doesn't apply the rules for unary operators.
My opinion is that const use in the kernel should almost always have whitespace before and after it except when preceded by a open parenthesis or a newline.
I totally agree.
Re: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
In reply to Joe PerchesQuoted 3 lines · Joe Perches
My opinion is that const use in the kernel should almost always have whitespace before and after it except when preceded by a open parenthesis or a newline.
So it shall be "void * const foo" (16k occurrences in the kernel) instead of "void *const foo" (3k occurrences)?
Re: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
Quoted 7 lines · Max Kellermann
Quoted 3 lines · Joe Perches
My opinion is that const use in the kernel should almost always have whitespace before and after it except when preceded by a open parenthesis or a newline.
So it shall be "void * const foo" (16k occurrences in the kernel) instead of "void *const foo" (3k occurrences)?
I think so.
$ git grep -P -oh "\bconst\s*\*" | sort | uniq -c | sort -rn | head -3
2538 const *
349 const*
20 const *
$ git grep -P -oh "\*\s*const\b" | sort | uniq -c | sort -rn | head -3
16677 * const
2912 *const
8 * constDocumentation/process/coding-style.rst doesn't mention const. Maybe it should.
Greg Kroah-Hartman
maintainerRe: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
In reply to Max KellermannQuoted 3 lines · Max Kellermann
This allows passing arrays of const pointers. The goal is to make lots of global variables "const" to allow them to live in the ".rodata" section.
I'm all for doing this type of work, but this is going to be rough. You sent patch 6/7 that hit almost all subsystems at once :(
Also, the code:
drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 180
Quoted 5 lines
drivers/base/base.h +2
-2-int driver_add_groups (struct device_driver *drv,const struct attribute_group **groups); -void driver_remove_groups (struct device_driver *drv,const struct attribute_group **groups); +int driver_add_groups (struct device_driver *drv,const struct attribute_group *const *groups); +void driver_remove_groups (struct device_driver *drv,const struct attribute_group *const *groups);void device_driver_detach (struct device *dev);
"*const*groups"? That's a parsing nightmare, really hard for humans to
read and understand. Doesn't checkpatch complain about this?
thanks,
greg k-h
Re: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
Quoted 2 lines · Greg Kroah-Hartman
I'm all for doing this type of work, but this is going to be rough. You sent patch 6/7 that hit almost all subsystems at once :(
I wasn't sure whether splitting patches was desired. In the past, I was often asked to fold multiple patches into one. There are so many opinions :-) but I'll gladly change to whatever is asked.
Quoted 2 lines
"*const*groups"? That's a parsing nightmare, really hard for humans to
read and understand. Doesn't checkpatch complain about this?
No. I'll change the coding style (and maybe take some time to fix checkpatch?)
Greg Kroah-Hartman
maintainerRe: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
In reply to Greg Kroah-HartmanQuoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Max Kellermann
This allows passing arrays of const pointers. The goal is to make lots of global variables "const" to allow them to live in the ".rodata" section.
I'm all for doing this type of work, but this is going to be rough. You sent patch 6/7 that hit almost all subsystems at once :(
The way to do this right is one-subsystem-at-a-time, right? Why not start there, doing it cleanly, and then at the end, change the driver core and then just the subsystem pointers? That should be much simpler, easier to review and verify, and many more changes (and probably take a kernel release or two to get through.)
thanks,
greg k-h
Re: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
In reply to Greg Kroah-HartmanQuoted 2 lines · Greg Kroah-Hartman
"*const*groups"? That's a parsing nightmare, really hard for humans to
read and understand. Doesn't checkpatch complain about this?
No, checkpatch does not implement a check/warning for this style (see my other email). There's no rule for this in coding-style.rst. Should there be one?
kernel test robot
build botRe: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const
In reply to Max Kellermannkernel test robot noticed the following build warnings:
Hi Max,
kernel test robot noticed the following build warnings:
[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on driver-core/driver-core-next driver-core/driver-core-linus tty/tty-testing tty/tty-next tty/tty-linus abelloni/rtc-next axboe-block/for-next linus/master v6.6-rc5 next-20231009] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Max-Kellermann/drivers-hwmon-add-local-variable-for-newly-allocated-attribute_group/20231010-010051 base: driver-core/driver-core-testing patch link: https://lore.kernel.org/r/20231009165741.746184-6-max.kellermann%40ionos.com patch subject: [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231010/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231010/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> block/genhd.c:399: warning: Function parameter or member 'const*groups' not described in 'device_add_disk' >> block/genhd.c:399: warning: Excess function parameter 'groups' description in 'device_add_disk' -- >> drivers/base/bus.c:1269: warning: Function parameter or member 'const*groups' not described in 'subsys_system_register' >> drivers/base/bus.c:1269: warning: Excess function parameter 'groups' description in 'subsys_system_register' >> drivers/base/bus.c:1287: warning: Function parameter or member 'const*groups' not described in 'subsys_virtual_register' >> drivers/base/bus.c:1287: warning: Excess function parameter 'groups' description in 'subsys_virtual_register' -- >> drivers/base/core.c:2808: warning: Function parameter or member 'const*groups' not described in 'devm_device_add_groups' >> drivers/base/core.c:2808: warning: Excess function parameter 'groups' description in 'devm_device_add_groups' >> drivers/base/core.c:4387: warning: Function parameter or member 'const*groups' not described in 'device_create_with_groups' >> drivers/base/core.c:4387: warning: Excess function parameter 'groups' description in 'device_create_with_groups' -- >> drivers/hwmon/hwmon.c:888: warning: Function parameter or member 'const*groups' not described in 'hwmon_device_register_with_groups' >> drivers/hwmon/hwmon.c:888: warning: Excess function parameter 'groups' description in 'hwmon_device_register_with_groups' >> drivers/hwmon/hwmon.c:915: warning: Function parameter or member 'const*extra_groups' not described in 'hwmon_device_register_with_info' >> drivers/hwmon/hwmon.c:915: warning: Excess function parameter 'extra_groups' description in 'hwmon_device_register_with_info' >> drivers/hwmon/hwmon.c:1008: warning: Function parameter or member 'const*groups' not described in 'devm_hwmon_device_register_with_groups' >> drivers/hwmon/hwmon.c:1008: warning: Excess function parameter 'groups' description in 'devm_hwmon_device_register_with_groups' >> drivers/hwmon/hwmon.c:1048: warning: Function parameter or member 'const*extra_groups' not described in 'devm_hwmon_device_register_with_info' >> drivers/hwmon/hwmon.c:1048: warning: Excess function parameter 'extra_groups' description in 'devm_hwmon_device_register_with_info' -- >> drivers/tty/tty_port.c:162: warning: Function parameter or member 'const*attr_grp' not described in 'tty_port_register_device_attr' >> drivers/tty/tty_port.c:162: warning: Excess function parameter 'attr_grp' description in 'tty_port_register_device_attr' >> drivers/tty/tty_port.c:185: warning: Function parameter or member 'const*attr_grp' not described in 'tty_port_register_device_attr_serdev' >> drivers/tty/tty_port.c:185: warning: Excess function parameter 'attr_grp' description in 'tty_port_register_device_attr_serdev' -- >> drivers/tty/tty_io.c:3216: warning: Function parameter or member 'const*attr_grp' not described in 'tty_register_device_attr' >> drivers/tty/tty_io.c:3216: warning: Excess function parameter 'attr_grp' description in 'tty_register_device_attr' -- >> drivers/infiniband/core/sysfs.c:1468: warning: Function parameter or member 'const*groups' not described in 'ib_port_register_client_groups' >> drivers/infiniband/core/sysfs.c:1468: warning: Excess function parameter 'groups' description in 'ib_port_register_client_groups' -- >> fs/sysfs/group.c:217: warning: Function parameter or member 'const*groups' not described in 'sysfs_create_groups' >> fs/sysfs/group.c:217: warning: Excess function parameter 'groups' description in 'sysfs_create_groups' >> fs/sysfs/group.c:235: warning: Function parameter or member 'const*groups' not described in 'sysfs_update_groups' >> fs/sysfs/group.c:235: warning: Excess function parameter 'groups' description in 'sysfs_update_groups' >> fs/sysfs/group.c:310: warning: Function parameter or member 'const*groups' not described in 'sysfs_remove_groups' >> fs/sysfs/group.c:310: warning: Excess function parameter 'groups' description in 'sysfs_remove_groups' >> fs/sysfs/group.c:566: warning: Function parameter or member 'const*groups' not described in 'sysfs_groups_change_owner' >> fs/sysfs/group.c:566: warning: Excess function parameter 'groups' description in 'sysfs_groups_change_owner'
vim +399 block/genhd.c
9301fe734384990e block/genhd.c Christoph Hellwig 2020-09-21 386
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 387 /**
d1254a8749711e0d block/genhd.c Christoph Hellwig 2021-08-04 388 * device_add_disk - add disk information to kernel list
e63a46bef01ff306 block/genhd.c Dan Williams 2016-06-15 389 * @parent: parent device for the disk
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 390 * @disk: per-device partitioning information
fef912bf860e8e7e block/genhd.c Hannes Reinecke 2018-09-28 391 * @groups: Additional per-device sysfs groups
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 392 *
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 393 * This function registers the partitioning information in @disk
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 394 * with the kernel.
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 395 */
278167fd2f8ffe67 block/genhd.c Luis Chamberlain 2021-11-09 396 int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
0d486e8e4d6c22b5 block/genhd.c Max Kellermann 2023-10-09 397 const struct attribute_group *const*groups)
d1254a8749711e0d block/genhd.c Christoph Hellwig 2021-08-04 398
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 @399 {
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 400 struct device *ddev = disk_to_dev(disk);
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 401 int ret;
cf0ca9fe5dd9e369 block/genhd.c Peter Zijlstra 2008-04-30 402
69fe0f29892077f1 block/genhd.c Ming Lei 2022-03-04 403 /* Only makes sense for bio-based to set ->poll_bio */
69fe0f29892077f1 block/genhd.c Ming Lei 2022-03-04 404 if (queue_is_mq(disk->queue) && disk->fops->poll_bio)
69fe0f29892077f1 block/genhd.c Ming Lei 2022-03-04 405 return -EINVAL;
69fe0f29892077f1 block/genhd.c Ming Lei 2022-03-04 406
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 407 /*
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 408 * The disk queue should now be all set with enough information about
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 409 * the device for the elevator code to pick an adequate default
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 410 * elevator if one is needed, that is, for devices requesting queue
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 411 * registration.
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 412 */
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 413 elevator_init_mq(disk->queue);
737eb78e82d52d35 block/genhd.c Damien Le Moal 2019-09-05 414
9f4107b07b17b5ee block/genhd.c Jens Axboe 2023-04-14 415 /* Mark bdev as having a submit_bio, if needed */
9f4107b07b17b5ee block/genhd.c Jens Axboe 2023-04-14 416 disk->part0->bd_has_submit_bio = disk->fops->submit_bio != NULL;
9f4107b07b17b5ee block/genhd.c Jens Axboe 2023-04-14 417
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 418 /*
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 419 * If the driver provides an explicit major number it also must provide
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 420 * the number of minors numbers supported, and those will be used to
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 421 * setup the gendisk.
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 422 * Otherwise just allocate the device numbers for both the whole device
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 423 * and all partitions from the extended dev_t space.
3e1a7ff8a0a7b948 block/genhd.c Tejun Heo 2008-08-25 424 */
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 425 ret = -EINVAL;
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 426 if (disk->major) {
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 427 if (WARN_ON(!disk->minors))
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 428 goto out_exit_elevator;
2e3c73fa0c419f62 block/genhd.c Christoph Hellwig 2021-05-21 429
2e3c73fa0c419f62 block/genhd.c Christoph Hellwig 2021-05-21 430 if (disk->minors > DISK_MAX_PARTS) {
2e3c73fa0c419f62 block/genhd.c Christoph Hellwig 2021-05-21 431 pr_err("block: can't allocate more than %d partitions\n",
2e3c73fa0c419f62 block/genhd.c Christoph Hellwig 2021-05-21 432 DISK_MAX_PARTS);
2e3c73fa0c419f62 block/genhd.c Christoph Hellwig 2021-05-21 433 disk->minors = DISK_MAX_PARTS;
2e3c73fa0c419f62 block/genhd.c Christoph Hellwig 2021-05-21 434 }
e338924bd05d6e71 block/genhd.c Tetsuo Handa 2021-12-17 435 if (disk->first_minor + disk->minors > MINORMASK + 1)
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 436 goto out_exit_elevator;
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 437 } else {
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 438 if (WARN_ON(disk->minors))
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 439 goto out_exit_elevator;
3e1a7ff8a0a7b948 block/genhd.c Tejun Heo 2008-08-25 440
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 441 ret = blk_alloc_ext_minor();
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 442 if (ret < 0)
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 443 goto out_exit_elevator;
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 444 disk->major = BLOCK_EXT_MAJOR;
539711d7d6fe382a block/genhd.c Christoph Hellwig 2021-08-24 445 disk->first_minor = ret;
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 446 }
7c3f828b522b07ad block/genhd.c Christoph Hellwig 2021-05-21 447
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 448 /* delay uevents, until we scanned partition table */
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 449 dev_set_uevent_suppress(ddev, 1);
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 450
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 451 ddev->parent = parent;
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 452 ddev->groups = groups;
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 453 dev_set_name(ddev, "%s", disk->disk_name);
8235b5c1e8c1c053 block/genhd.c Christoph Hellwig 2021-08-18 454 if (!(disk->flags & GENHD_FL_HIDDEN))
8235b5c1e8c1c053 block/genhd.c Christoph Hellwig 2021-08-18 455 ddev->devt = MKDEV(disk->major, disk->first_minor);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 456 ret = device_add(ddev);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 457 if (ret)
99d8690aae4b2f0d block/genhd.c Christoph Hellwig 2021-12-21 458 goto out_free_ext_minor;
99d8690aae4b2f0d block/genhd.c Christoph Hellwig 2021-12-21 459
99d8690aae4b2f0d block/genhd.c Christoph Hellwig 2021-12-21 460 ret = disk_alloc_events(disk);
99d8690aae4b2f0d block/genhd.c Christoph Hellwig 2021-12-21 461 if (ret)
99d8690aae4b2f0d block/genhd.c Christoph Hellwig 2021-12-21 462 goto out_device_del;
99d8690aae4b2f0d block/genhd.c Christoph Hellwig 2021-12-21 463
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 464 ret = sysfs_create_link(block_depr, &ddev->kobj,
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 465 kobject_name(&ddev->kobj));
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 466 if (ret)
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 467 goto out_device_del;
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 468
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 469 /*
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 470 * avoid probable deadlock caused by allocating memory with
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 471 * GFP_KERNEL in runtime_resume callback of its all ancestor
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 472 * devices
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 473 */
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 474 pm_runtime_set_memalloc_noio(ddev, true);
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 475
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 476 disk->part0->bd_holder_dir =
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 477 kobject_create_and_add("holders", &ddev->kobj);
fe7d064fa3faec5d block/genhd.c Luis Chamberlain 2021-11-03 478 if (!disk->part0->bd_holder_dir) {
fe7d064fa3faec5d block/genhd.c Luis Chamberlain 2021-11-03 479 ret = -ENOMEM;
ff53cd52d9bdbf40 block/genhd.c Thomas Weißschuh 2023-03-18 480 goto out_del_block_link;
fe7d064fa3faec5d block/genhd.c Luis Chamberlain 2021-11-03 481 }
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 482 disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
fe7d064fa3faec5d block/genhd.c Luis Chamberlain 2021-11-03 483 if (!disk->slave_dir) {
fe7d064fa3faec5d block/genhd.c Luis Chamberlain 2021-11-03 484 ret = -ENOMEM;
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 485 goto out_put_holder_dir;
fe7d064fa3faec5d block/genhd.c Luis Chamberlain 2021-11-03 486 }
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 487
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 488 ret = blk_register_queue(disk);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 489 if (ret)
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 490 goto out_put_slave_dir;
75f4dca59694dfe2 block/genhd.c Christoph Hellwig 2021-08-18 491
9f18db572c97bc32 block/genhd.c Christoph Hellwig 2021-11-22 492 if (!(disk->flags & GENHD_FL_HIDDEN)) {
8235b5c1e8c1c053 block/genhd.c Christoph Hellwig 2021-08-18 493 ret = bdi_register(disk->bdi, "%u:%u",
8235b5c1e8c1c053 block/genhd.c Christoph Hellwig 2021-08-18 494 disk->major, disk->first_minor);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 495 if (ret)
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 496 goto out_unregister_queue;
8235b5c1e8c1c053 block/genhd.c Christoph Hellwig 2021-08-18 497 bdi_set_owner(disk->bdi, ddev);
9d5ee6767c857622 block/genhd.c Christoph Hellwig 2021-08-18 498 ret = sysfs_create_link(&ddev->kobj,
9d5ee6767c857622 block/genhd.c Christoph Hellwig 2021-08-18 499 &disk->bdi->dev->kobj, "bdi");
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 500 if (ret)
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 501 goto out_unregister_bdi;
8235b5c1e8c1c053 block/genhd.c Christoph Hellwig 2021-08-18 502
e5cfefa97bccf956 block/genhd.c Yu Kuai 2023-02-17 503 /* Make sure the first partition scan will be proceed */
e5cfefa97bccf956 block/genhd.c Yu Kuai 2023-02-17 504 if (get_capacity(disk) && !(disk->flags & GENHD_FL_NO_PART) &&
e5cfefa97bccf956 block/genhd.c Yu Kuai 2023-02-17 505 !test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
e5cfefa97bccf956 block/genhd.c Yu Kuai 2023-02-17 506 set_bit(GD_NEED_PART_SCAN, &disk->state);
e5cfefa97bccf956 block/genhd.c Yu Kuai 2023-02-17 507
9d5ee6767c857622 block/genhd.c Christoph Hellwig 2021-08-18 508 bdev_add(disk->part0, ddev->devt);
e16e506ccd673a3a block/genhd.c Christoph Hellwig 2021-11-22 509 if (get_capacity(disk))
05bdb9965305bbfd block/genhd.c Christoph Hellwig 2023-06-08 510 disk_scan_partitions(disk, BLK_OPEN_READ);
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 511
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 512 /*
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 513 * Announce the disk and partitions after all partitions are
8235b5c1e8c1c053 block/genhd.c Christoph Hellwig 2021-08-18 514 * created. (for hidden disks uevents remain suppressed forever)
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 515 */
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 516 dev_set_uevent_suppress(ddev, 0);
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 517 disk_uevent(disk, KOBJ_ADD);
a0a6314ae774f8a5 block/genhd.c Christoph Hellwig 2022-10-10 518 } else {
a0a6314ae774f8a5 block/genhd.c Christoph Hellwig 2022-10-10 519 /*
a0a6314ae774f8a5 block/genhd.c Christoph Hellwig 2022-10-10 520 * Even if the block_device for a hidden gendisk is not
a0a6314ae774f8a5 block/genhd.c Christoph Hellwig 2022-10-10 521 * registered, it needs to have a valid bd_dev so that the
a0a6314ae774f8a5 block/genhd.c Christoph Hellwig 2022-10-10 522 * freeing of the dynamic major works.
a0a6314ae774f8a5 block/genhd.c Christoph Hellwig 2022-10-10 523 */
a0a6314ae774f8a5 block/genhd.c Christoph Hellwig 2022-10-10 524 disk->part0->bd_dev = MKDEV(disk->major, disk->first_minor);
8ddcd653257c18a6 block/genhd.c Christoph Hellwig 2017-11-02 525 }
52b85909f85d06ef block/genhd.c Christoph Hellwig 2021-08-18 526
75f4dca59694dfe2 block/genhd.c Christoph Hellwig 2021-08-18 527 disk_update_readahead(disk);
77ea887e433ad838 block/genhd.c Tejun Heo 2010-12-08 528 disk_add_events(disk);
76792055c4c8b247 block/genhd.c Christoph Hellwig 2022-02-15 529 set_bit(GD_ADDED, &disk->state);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 530 return 0;
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 531
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 532 out_unregister_bdi:
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 533 if (!(disk->flags & GENHD_FL_HIDDEN))
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 534 bdi_unregister(disk->bdi);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 535 out_unregister_queue:
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 536 blk_unregister_queue(disk);
fa81cbafbf5764ad block/genhd.c Chen Zhongjin 2022-10-29 537 rq_qos_exit(disk->queue);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 538 out_put_slave_dir:
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 539 kobject_put(disk->slave_dir);
d90db3b1c8676bc8 block/genhd.c Christoph Hellwig 2022-11-15 540 disk->slave_dir = NULL;
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 541 out_put_holder_dir:
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 542 kobject_put(disk->part0->bd_holder_dir);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 543 out_del_block_link:
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 544 sysfs_remove_link(block_depr, dev_name(ddev));
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 545 out_device_del:
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 546 device_del(ddev);
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 547 out_free_ext_minor:
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 548 if (disk->major == BLOCK_EXT_MAJOR)
83cbce9574462c6b block/genhd.c Luis Chamberlain 2021-08-18 549 blk_free_ext_minor(disk->first_minor);
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 550 out_exit_elevator:
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 551 if (disk->queue->elevator)
02341a08c9dec5a8 block/genhd.c Yu Kuai 2022-10-22 552 elevator_exit(disk->queue);
278167fd2f8ffe67 block/genhd.c Luis Chamberlain 2021-11-09 553 return ret;
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 554 }
e63a46bef01ff306 block/genhd.c Dan Williams 2016-06-15 555 EXPORT_SYMBOL(device_add_disk);
^1da177e4c3f4152 drivers/block/genhd.c Linus Torvalds 2005-04-16 556 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 7/7 block, drivers: make lots of attribute_group globals const
In reply to Max KellermannThis moves those variables to the ".rodata" section which reduces the kernel size a bit and protects the variables by putting them on read-only pages at runtime.
--- block/blk-sysfs.c | 6 +++--- block/genhd.c | 4 ++-- block/partitions/core.c | 2 +- drivers/base/cacheinfo.c | 2 +- drivers/block/loop.c | 2 +- drivers/block/rbd.c | 4 ++-- drivers/input/input.c | 2 +- drivers/input/serio/serio.c | 2 +- drivers/pci/pci-sysfs.c | 8 ++++---- drivers/pci/pci.h | 6 +++--- drivers/pps/sysfs.c | 2 +- drivers/rtc/sysfs.c | 2 +- drivers/tty/serial/8250/8250_port.c | 2 +- fs/ocfs2/cluster/sys.c | 2 +- include/linux/khugepaged.h | 2 +- include/linux/pps_kernel.h | 2 +- mm/khugepaged.c | 2 +- 17 files changed, 26 insertions(+), 26 deletions(-)
block/blk-sysfs.c +3 -3
@@ -699,12 +699,12 @@ static umode_t blk_mq_queue_attr_visible(struct kobject *kobj,return attr->mode; } -static struct attribute_group queue_attr_group = { +static const struct attribute_group queue_attr_group = { .attrs = queue_attrs, .is_visible = queue_attr_visible, }; -static struct attribute_group blk_mq_queue_attr_group = { +static const struct attribute_group blk_mq_queue_attr_group = { .attrs = blk_mq_queue_attrs, .is_visible = blk_mq_queue_attr_visible, };
@@ -750,7 +750,7 @@ static const struct sysfs_ops queue_sysfs_ops = { .store = queue_attr_store, }; -static const struct attribute_group *blk_queue_attr_groups[] = { +static const struct attribute_group *const blk_queue_attr_groups[] = { &queue_attr_group, &blk_mq_queue_attr_group,NULL
block/genhd.c +2 -2
@@ -1115,12 +1115,12 @@ static umode_t disk_visible(struct kobject *kobj, struct attribute *a, int n)return a->mode; } -static struct attribute_group disk_attr_group = { +static const struct attribute_group disk_attr_group = { .attrs = disk_attrs, .is_visible = disk_visible, }; -static const struct attribute_group *disk_attr_groups[] = { +static const struct attribute_group *const disk_attr_groups[] = { &disk_attr_group, #ifdef CONFIG_BLK_DEV_IO_TRACE &blk_trace_attr_group,
block/partitions/core.c +1 -1
@@ -232,7 +232,7 @@ static const struct attribute_group part_attr_group = { .attrs = part_attrs, }; -static const struct attribute_group *part_attr_groups[] = { +static const struct attribute_group *const part_attr_groups[] = { &part_attr_group, #ifdef CONFIG_BLK_DEV_IO_TRACE &blk_trace_attr_group,
drivers/base/cacheinfo.c +1 -1
@@ -786,7 +786,7 @@ static const struct attribute_group cache_default_group = { .is_visible = cache_default_attrs_is_visible, }; -static const struct attribute_group *cache_default_groups[] = { +static const struct attribute_group *const cache_default_groups[] = { &cache_default_group,NULL , };
drivers/block/loop.c +1 -1
@@ -736,7 +736,7 @@ static struct attribute *loop_attrs[] = { NULL, }; -static struct attribute_group loop_attribute_group = { +static const struct attribute_group loop_attribute_group = { .name ="loop" , .attrs= loop_attrs, };
drivers/block/rbd.c +2 -2
@@ -5246,11 +5246,11 @@ static struct attribute *rbd_attrs[] = { NULL }; -static struct attribute_group rbd_attr_group = { +static const struct attribute_group rbd_attr_group = { .attrs = rbd_attrs, }; -static const struct attribute_group *rbd_attr_groups[] = { +static const struct attribute_group *const rbd_attr_groups[] = { &rbd_attr_group,NULL };
drivers/input/input.c +1 -1
@@ -1597,7 +1597,7 @@ static const struct attribute_group input_dev_caps_attr_group = { .attrs = input_dev_caps_attrs, }; -static const struct attribute_group *input_dev_attr_groups[] = { +static const struct attribute_group *const input_dev_attr_groups[] = { &input_dev_attr_group, &input_dev_id_attr_group, &input_dev_caps_attr_group,
drivers/input/serio/serio.c +1 -1
@@ -474,7 +474,7 @@ static const struct attribute_group serio_device_attr_group = { .attrs = serio_device_attrs, }; -static const struct attribute_group *serio_device_attr_groups[] = { +static const struct attribute_group *const serio_device_attr_groups[] = { &serio_id_attr_group, &serio_device_attr_group,NULL
drivers/pci/pci-sysfs.c +4 -4
@@ -455,7 +455,7 @@ static const struct attribute_group pci_bus_group = { .attrs = pci_bus_attrs, }; -const struct attribute_group *pci_bus_groups[] = { +const struct attribute_group *const pci_bus_groups[] = { &pci_bus_group,NULL , };
@@ -647,7 +647,7 @@ static const struct attribute_group pcibus_group = { .attrs = pcibus_attrs, }; -const struct attribute_group *pcibus_groups[] = { +const struct attribute_group *const pcibus_groups[] = { &pcibus_group,NULL , };
@@ -1604,7 +1604,7 @@ static const struct attribute_group pci_dev_group = { .attrs = pci_dev_attrs, }; -const struct attribute_group *pci_dev_groups[] = { +const struct attribute_group *const pci_dev_groups[] = { &pci_dev_group, &pci_dev_config_attr_group, &pci_dev_rom_attr_group,
@@ -1641,7 +1641,7 @@ static const struct attribute_group pcie_dev_attr_group = { .is_visible = pcie_dev_attrs_are_visible, }; -static const struct attribute_group *pci_dev_attr_groups[] = { +static const struct attribute_group *const pci_dev_attr_groups[] = { &pci_dev_attr_group, &pci_dev_hp_attr_group, #ifdef CONFIG_PCI_IOV
drivers/pci/pci.h +3 -3
@@ -182,10 +182,10 @@ static inline int pci_no_d1d2(struct pci_dev *dev)return (dev->no_d1d2 || parent_dstates); } -extern const struct attribute_group *pci_dev_groups[]; -extern const struct attribute_group *pcibus_groups[]; +extern const struct attribute_group *const pci_dev_groups[]; +extern const struct attribute_group *const pcibus_groups[];extern const struct device_type pci_dev_type; -extern const struct attribute_group *pci_bus_groups[]; +extern const struct attribute_group *const pci_bus_groups[];extern unsigned long pci_hotplug_io_size;extern unsigned long pci_hotplug_mmio_size;
drivers/pps/sysfs.c +1 -1
@@ -93,7 +93,7 @@ static const struct attribute_group pps_group = { .attrs = pps_attrs, }; -const struct attribute_group *pps_groups[] = { +const struct attribute_group *const pps_groups[] = { &pps_group,NULL , };
drivers/rtc/sysfs.c +1 -1
@@ -303,7 +303,7 @@ static struct attribute_group rtc_attr_group = { .attrs = rtc_attrs, }; -static const struct attribute_group *rtc_attr_groups[] = { +static const struct attribute_group *const rtc_attr_groups[] = { &rtc_attr_group,NULL };
drivers/tty/serial/8250/8250_port.c +1 -1
@@ -3187,7 +3187,7 @@ static struct attribute *serial8250_dev_attrs[] = { NULL }; -static struct attribute_group serial8250_dev_attr_group = { +static const struct attribute_group serial8250_dev_attr_group = { .attrs = serial8250_dev_attrs, };
fs/ocfs2/cluster/sys.c +1 -1
@@ -31,7 +31,7 @@ static struct attribute *o2cb_attrs[] = { NULL, }; -static struct attribute_group o2cb_attr_group = { +static const struct attribute_group o2cb_attr_group = { .attrs = o2cb_attrs, };
include/linux/khugepaged.h +1 -1
@@ -5,7 +5,7 @@#include <linux/sched/coredump.h> /* MMF_VM_HUGEPAGE */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE -extern struct attribute_group khugepaged_attr_group; +extern const struct attribute_group khugepaged_attr_group;extern int khugepaged_init (void );extern void khugepaged_destroy (void );
include/linux/pps_kernel.h +1 -1
@@ -66,7 +66,7 @@ struct pps_device {* Global variables */ -extern const struct attribute_group *pps_groups[]; +extern const struct attribute_group *const pps_groups[];/* * Internal functions.
mm/khugepaged.c +1 -1
@@ -339,7 +339,7 @@ static struct attribute *khugepaged_attr[] = { NULL, }; -struct attribute_group khugepaged_attr_group = { +const struct attribute_group khugepaged_attr_group = { .attrs = khugepaged_attr, .name ="khugepaged" , };
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerRe: [PATCH 7/7] block, drivers: make lots of attribute_group globals const
Quoted 3 lines · Max Kellermann
This moves those variables to the ".rodata" section which reduces the kernel size a bit and protects the variables by putting them on read-only pages at runtime.
The kernel size should still be the same overall, you are just moving pointers from one section to another, right?
If not, what are the numbers, show them please.
But step back, are you SURE you can make these attribute group pointers const? They are modified by some subsystems by adding or removing items from the lists, so why does the core need to change for that?
thanks,
greg k-h
Re: [PATCH 7/7] block, drivers: make lots of attribute_group globals const
Quoted 10 lines · Greg Kroah-Hartman
Quoted 3 lines · Max Kellermann
This moves those variables to the ".rodata" section which reduces the kernel size a bit and protects the variables by putting them on read-only pages at runtime.
The kernel size should still be the same overall, you are just moving pointers from one section to another, right?
If not, what are the numbers, show them please.
Before this patch series:
text data bss dec hex filename
10645342 6836166 12476420 29957928 1c91f28 vmlinux
After:
text data bss dec hex filename
10645342 6835398 12476420 29957160 1c91c28 vmlinux
(Config attached if you wish to reproduce. I'm using stock GCC from Debian Bookworm.)
It's only a few hundred bytes, and I havn't really dug deep enough to explain to you why this is - my goal was (semantic) const-correctness and .rodata protection, but those numbers are a side effect that exists.
Quoted 3 lines
But step back, are you SURE you can make these attribute group pointers const? They are modified by some subsystems by adding or removing items from the lists, so why does the core need to change for that?
Some few do modify them, but they do not modify those pointers; they allocate a new one (the 3 I sbumitted a patch for) or they modify global variables (arch/pmu) which I'm not going to make "const". But most globals can indeed be made "const".
Greg KH
maintainerQuoted 2 lines · Max Kellermann
This avoids overloading the "groups" variable for three different purposes
What 3 different purposes?
And you sent a patch series that hit a lot of different subsystems and maintainers all at once, but you didn't cc: all of us. Who is supposed to take these?
But step back, _WHY_ are all of these changes needed? I don't see a cover letter explaining the rational, and on their own, they really don't do anything, so it's really confusing as to what is going on here.
thanks,
greg k-h
Quoted 1 line · Greg KH
What 3 different purposes?
The variable gets initialized 3 times with different (unrelated) values:
1. count old rtc->dev.groups
2. count grps
3. allocate new rtc->dev.groups
This coding style is confusing and error prone. The code gets simpler with this patch, because the cognitive load of understanding a "count_attribute_groups()" call is lower than reading the "while" loop and figuring out why it's there.
But I really wrote this patch because after making "rtc->dev.groups" const, I cannot any longer assign it to "groups", because that variable must remain non-const.
Alexandre Belloni
maintainerQuoted 13 lines · Max Kellermann
This avoids overloading the "groups" variable for three different purposes
Signed-off-by Max Kellermann <[email protected]>--- drivers/rtc/sysfs.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)drivers/rtc/sysfs.c +0
-0
drivers/rtc/sysfs.c const struct attribute_group **rtc_get_dev_attribute_groups(void) · line 316
Quoted 4 lines
drivers/rtc/sysfs.c +1
-0@@ -313,21 +313,25 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void)return rtc_attr_groups; } +static size_t count_attribute_groups (const struct attribute_group *const *groups)
Shouldn't that live out of the rtc subsystem?
Quoted 32 lines
drivers/rtc/sysfs.c +11
-8+{ +size_t count =0 ; + +for (; *groups; ++groups) + ++count; +return count; +} +int rtc_add_groups (struct rtc_device *rtc,const struct attribute_group **grps) { -size_t old_cnt =0 , add_cnt =0 , new_cnt; +size_t old_cnt, add_cnt, new_cnt;const struct attribute_group **groups, **old;if (!grps)return -EINVAL ; - groups = rtc->dev.groups; -if (groups) -for (; *groups; groups++) - old_cnt++; - -for (groups = grps; *groups; groups++) - add_cnt++; + old_cnt = rtc->dev.groups ?count_attribute_groups (rtc->dev.groups) :0 ; + add_cnt =count_attribute_groups (grps); new_cnt = old_cnt + add_cnt +1 ; groups =devm_kcalloc (&rtc->dev, new_cnt,sizeof (*groups),GFP_KERNEL );Signature · 1 line
2.39.2
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 1 line · Alexandre Belloni
Shouldn't that live out of the rtc subsystem?
You suggest making this a global function? Sure, if that's preferred, I'll change it. Whose decision is this?