Re: [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array
From: yanjun.zhu
Date: Wed Feb 18 2026 - 19:53:55 EST
On 2/17/26 2:26 PM, Heiner Kallweit wrote:
This prepares for making struct device member groups a constant array.
The assignment groups = rtc->dev.groups would result in a "discarding
const qualifier" warning with this change.
No functional change intended.
Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx>
---
drivers/rtc/sysfs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
index 4ab05e105a7..ae5e1252b4c 100644
--- a/drivers/rtc/sysfs.c
+++ b/drivers/rtc/sysfs.c
@@ -308,7 +308,7 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void)
int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
{
size_t old_cnt = 0, add_cnt = 0, new_cnt;
- const struct attribute_group **groups, **old;
+ const struct attribute_group **groups, *const *old;
if (grps) {
for (groups = grps; *groups; groups++)
@@ -320,9 +320,9 @@ int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
return -EINVAL;
}
- groups = rtc->dev.groups;
- if (groups)
- for (; *groups; groups++)
+ old = rtc->dev.groups;
+ if (old)
+ while (*old++)
old_cnt++;
The change from for (; *groups; groups++) to while (*old++) is not functionally equivalent. In the while version, the post-increment old++ executes even when *old is NULL. This leaves the pointer old pointing one element past the NULL terminator. While old_cnt remains correct, this is a side-effect-heavy idiom that differs from standard kernel patterns and could be fragile if old is used later in the function.
Best Regards,
Zhu Yanjun
new_cnt = old_cnt + add_cnt + 1;