summaryrefslogtreecommitdiff
path: root/drivers/rtc/sysfs.c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2025-07-02 10:32:24 +0300
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2025-07-22 13:06:01 +0200
commitbbe8d4fef308cddd11b2e766c8710d318334b88b (patch)
tree38c223e9a1226eb9da8d9c7bb1867a4ccc6967f1 /drivers/rtc/sysfs.c
parent4dda8df717b7e5ad89de79844e5491aaf78b44da (diff)
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>
Diffstat (limited to 'drivers/rtc/sysfs.c')
-rw-r--r--drivers/rtc/sysfs.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
index 86d1140b4f39..bf98a89d0e4e 100644
--- a/drivers/rtc/sysfs.c
+++ b/drivers/rtc/sysfs.c
@@ -314,17 +314,21 @@ 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;
- if (!grps)
+ if (grps) {
+ for (groups = grps; *groups; groups++)
+ add_cnt++;
+ /* No need to modify current groups if nothing new is provided */
+ if (add_cnt == 0)
+ return 0;
+ } else {
return -EINVAL;
+ }
groups = rtc->dev.groups;
if (groups)
for (; *groups; groups++)
old_cnt++;
- for (groups = grps; *groups; groups++)
- add_cnt++;
-
new_cnt = old_cnt + add_cnt + 1;
groups = devm_kcalloc(&rtc->dev, new_cnt, sizeof(*groups), GFP_KERNEL);
if (!groups)