diff mbox series

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

Message ID 20231009165741.746184-4-max.kellermann@ionos.com (mailing list archive)
State Handled Elsewhere
Headers show
Series None | expand

Commit Message

Max Kellermann Oct. 9, 2023, 4:57 p.m. UTC
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@ionos.com>
---
 drivers/counter/counter-sysfs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Greg KH Oct. 9, 2023, 5:28 p.m. UTC | #1
On Mon, Oct 09, 2023 at 06:57:37PM +0200, Max Kellermann wrote:
> 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
diff mbox series

Patch

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;