Skip to content

Commit bbe8d4f

Browse files
andy-shevalexandrebelloni
authored andcommitted
rtc: sysfs: Bail out earlier if no new groups provided
When there is no new groups provided, no need to reallocate memory, copy the old ones and free them in order to do nothing. Do nothing instead. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20250702073224.2684097-1-andriy.shevchenko@linux.intel.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 4dda8df commit bbe8d4f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

drivers/rtc/sysfs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,21 @@ int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
314314
size_t old_cnt = 0, add_cnt = 0, new_cnt;
315315
const struct attribute_group **groups, **old;
316316

317-
if (!grps)
317+
if (grps) {
318+
for (groups = grps; *groups; groups++)
319+
add_cnt++;
320+
/* No need to modify current groups if nothing new is provided */
321+
if (add_cnt == 0)
322+
return 0;
323+
} else {
318324
return -EINVAL;
325+
}
319326

320327
groups = rtc->dev.groups;
321328
if (groups)
322329
for (; *groups; groups++)
323330
old_cnt++;
324331

325-
for (groups = grps; *groups; groups++)
326-
add_cnt++;
327-
328332
new_cnt = old_cnt + add_cnt + 1;
329333
groups = devm_kcalloc(&rtc->dev, new_cnt, sizeof(*groups), GFP_KERNEL);
330334
if (!groups)

0 commit comments

Comments
 (0)