lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231009165741.746184-1-max.kellermann@ionos.com>
Date:   Mon,  9 Oct 2023 18:57:34 +0200
From:   Max Kellermann <max.kellermann@...os.com>
To:     Alessandro Zummo <a.zummo@...ertech.it>,
        Alexandre Belloni <alexandre.belloni@...tlin.com>
Cc:     Max Kellermann <max.kellermann@...os.com>,
        linux-rtc@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups()

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

Signed-off-by: Max Kellermann <max.kellermann@...os.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ