timekeeping: Unwind aux clock sysfs children on failure
PATCH 1/1 timekeeping: Unwind aux clock sysfs children on failure
tk_aux_sysfs_init() creates one child kobject per auxiliary clock. If a later child or sysfs group creation fails, the current error path only puts the parent kobjects and leaves earlier children and groups behind.
Store the child kobjects during init and remove the successfully created groups and kobjects on failure.
--- kernel/time/timekeeping.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
kernel/time/timekeeping.c +15 -6
@@ -3313,7 +3313,9 @@ static const struct attribute_group aux_clock_enable_attr_group = {static int __init tk_aux_sysfs_init (void ) {struct kobject *auxo, *tko =kobject_create_and_add ("time" , kernel_kobj); +struct kobject *clks[MAX_AUX_CLOCKS ];int ret = -ENOMEM ; +int i;if (!tko)return ret;
@@ -3322,21 +3324,28 @@ static int __init tk_aux_sysfs_init(void)if (!auxo) goto err_clean; -for (int i =0 ; i <MAX_AUX_CLOCKS ; i++) { +for (i =0 ; i <MAX_AUX_CLOCKS ; i++) {char id[2 ] = { [0 ] ='0' + i, }; -struct kobject *clk =kobject_create_and_add (id, auxo); + clks[i] =kobject_create_and_add (id, auxo); -if (!clk) { +if (!clks[i]) { ret = -ENOMEM ; - goto err_clean; + goto err_clks; } - ret =sysfs_create_group (clk, &aux_clock_enable_attr_group); + ret =sysfs_create_group (clks[i], &aux_clock_enable_attr_group);if (ret) - goto err_clean; + goto err_clk; }return 0 ; +err_clk: +kobject_put (clks[i]); +err_clks: +while (--i >=0 ) { +sysfs_remove_group (clks[i], &aux_clock_enable_attr_group); +kobject_put (clks[i]); + } err_clean:kobject_put (auxo);kobject_put (tko);
Signature · 1 line
2.43.0
The following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: f2eee7e31ccd4bc87d047d8670cc2ec39cf36647 Gitweb: https://git.kernel.org/tip/f2eee7e31ccd4bc87d047d8670cc2ec39cf36647 Author: Yuho Choi <[email protected]> AuthorDate: Fri, 03 Jul 2026 12:53:37 -04:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 07 Jul 2026 23:26:58 +02:00
timekeeping: Unwind aux clock sysfs children on failure
tk_aux_sysfs_init() creates one child kobject per auxiliary clock. If a later child or sysfs group creation fails, the current error path only puts the parent kobjects and leaves earlier children and groups behind.
Store the child kobjects during init and remove the successfully created groups and kobjects on failure.
--- kernel/time/timekeeping.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
kernel/time/timekeeping.c +15 -6
@@ -3327,7 +3327,9 @@ static const struct attribute_group aux_clock_enable_attr_group = {static int __init tk_aux_sysfs_init (void ) {struct kobject *auxo, *tko =kobject_create_and_add ("time" , kernel_kobj); +struct kobject *clks[MAX_AUX_CLOCKS ];int ret = -ENOMEM ; +int i;if (!tko)return ret;
@@ -3336,21 +3338,28 @@ static int __init tk_aux_sysfs_init(void)if (!auxo) goto err_clean; -for (int i =0 ; i <MAX_AUX_CLOCKS ; i++) { +for (i =0 ; i <MAX_AUX_CLOCKS ; i++) {char id[2 ] = { [0 ] ='0' + i, }; -struct kobject *clk =kobject_create_and_add (id, auxo); + clks[i] =kobject_create_and_add (id, auxo); -if (!clk) { +if (!clks[i]) { ret = -ENOMEM ; - goto err_clean; + goto err_clks; } - ret =sysfs_create_group (clk, &aux_clock_enable_attr_group); + ret =sysfs_create_group (clks[i], &aux_clock_enable_attr_group);if (ret) - goto err_clean; + goto err_clk; }return 0 ; +err_clk: +kobject_put (clks[i]); +err_clks: +while (--i >=0 ) { +sysfs_remove_group (clks[i], &aux_clock_enable_attr_group); +kobject_put (clks[i]); + } err_clean:kobject_put (auxo);kobject_put (tko);