public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups()
@ 2023-10-09 16:57 Max Kellermann
  2023-10-09 16:57 ` [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group** Max Kellermann
                   ` (7 more replies)
  0 siblings, 8 replies; 32+ messages in thread
From: Max Kellermann @ 2023-10-09 16:57 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Max Kellermann, linux-rtc, linux-kernel

This avoids overloading the "groups" variable for three different
purposes

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 drivers/rtc/sysfs.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
index e3062c4d3f2c..617933d52324 100644
--- a/drivers/rtc/sysfs.c
+++ b/drivers/rtc/sysfs.c
@@ -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);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2023-10-10  8:24 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 4/7] drivers/counter: " Max Kellermann
2023-10-09 17:28   ` 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-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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox