[PATCH 4/7] drivers/counter: add local variable for newly allocated attribute_group**

From: Max Kellermann
Date: Mon Oct 09 2023 - 12:58:05 EST


This allows the compiler to keep the pointer in a register and
prepares for making the struct field "const".

Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
drivers/counter/counter-sysfs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c
index 42c523343d32..47e1e2c61cf0 100644
--- a/drivers/counter/counter-sysfs.c
+++ b/drivers/counter/counter-sysfs.c
@@ -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;
--
2.39.2