All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Kellermann <max.kellermann@ionos.com>
To: William Breathitt Gray <william.gray@linaro.org>
Cc: Max Kellermann <max.kellermann@ionos.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 4/7] drivers/counter: add local variable for newly allocated attribute_group**
Date: Mon,  9 Oct 2023 18:57:37 +0200	[thread overview]
Message-ID: <20231009165741.746184-4-max.kellermann@ionos.com> (raw)
In-Reply-To: <20231009165741.746184-1-max.kellermann@ionos.com>

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(-)

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


  parent reply	other threads:[~2023-10-09 16:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09 16:57 [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups() Max Kellermann
2023-10-09 16:57 ` [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group** Max Kellermann
2023-10-09 17:19   ` Guenter Roeck
2023-10-09 17:28     ` Max Kellermann
2023-10-09 19:36       ` Guenter Roeck
2023-10-09 17:27   ` Greg KH
2023-10-09 17:34     ` Max Kellermann
2023-10-09 16:57 ` [PATCH 3/7] drivers/extcon: " Max Kellermann
2023-10-09 17:28   ` Greg KH
2023-10-09 16:57 ` Max Kellermann [this message]
2023-10-09 17:28   ` [PATCH 4/7] drivers/counter: " Greg KH
2023-10-09 16:57 ` [PATCH 5/7] drivers/tty/serial_core: " Max Kellermann
2023-10-09 17:28   ` Greg Kroah-Hartman
2023-10-09 16:57 ` [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const Max Kellermann
2023-10-09 17:24   ` Guenter Roeck
2023-10-09 20:05     ` Max Kellermann
2023-10-10  5:59       ` Greg Kroah-Hartman
2023-10-10  6:48       ` Joe Perches
2023-10-10  6:57         ` Greg Kroah-Hartman
2023-10-10  7:38         ` Max Kellermann
2023-10-10  8:01           ` Joe Perches
2023-10-09 17:25   ` Greg Kroah-Hartman
2023-10-09 17:30     ` Max Kellermann
2023-10-09 17:31     ` Greg Kroah-Hartman
2023-10-09 20:20     ` Max Kellermann
2023-10-10  5:38   ` kernel test robot
2023-10-09 16:57 ` [PATCH 7/7] block, drivers: make lots of attribute_group globals const Max Kellermann
2023-10-09 17:30   ` Greg Kroah-Hartman
2023-10-09 17:40     ` Max Kellermann
2023-10-09 17:24 ` [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups() Greg KH
2023-10-09 18:01   ` Max Kellermann
2023-10-10  8:15 ` Alexandre Belloni
2023-10-10  8:24   ` Max Kellermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231009165741.746184-4-max.kellermann@ionos.com \
    --to=max.kellermann@ionos.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=william.gray@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.