timekeeping: Fix error code in tk_aux_sysfs_init()
PATCH 1/1 timekeeping: Fix error code in tk_aux_sysfs_init()
If kobject_create_and_add() fails on the first iteration, then the error code is set to -ENOMEM and that's good. But if it fails on the later iterations then "ret" is zero, which means success, but it should be -ENOMEM. Set the error code to -ENOMEM correctly.
--- kernel/time/timekeeping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/time/timekeeping.c +3 -1
@@ -3087,8 +3087,10 @@ static int __init tk_aux_sysfs_init(void)char id[2 ] = { [0 ] ='0' + i, };struct kobject *clk =kobject_create_and_add (id, auxo); -if (!clk) +if (!clk) { + ret = -ENOMEM ; goto err_clean; + } ret =sysfs_create_group (clk, &aux_clock_enable_attr_group);if (ret)
Signature · 1 line
2.51.0
Quoted 29 lines · Dan Carpenter
If
kobject_create_and_add()fails on the first iteration, then the error code is set to-ENOMEMand that's good. But if it fails on the later iterations then "ret" is zero, which means success, but it should be-ENOMEM. Set the error code to-ENOMEMcorrectly.Fixes 7b5ab04f035f ("timekeeping: Fix resource leak in tk_aux_sysfs_init() error paths")Signed-off-by Dan Carpenter <[email protected]>--- kernel/time/timekeeping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/time/timekeeping.c +3
-2@@ -3087,8 +3087,10 @@ static int __init tk_aux_sysfs_init(void)char id[2 ] = { [0 ] ='0' + i, };struct kobject *clk =kobject_create_and_add (id, auxo); -if (!clk) +if (!clk) { + ret = -ENOMEM ; goto err_clean; + } ret =sysfs_create_group (clk, &aux_clock_enable_attr_group);if (ret) --
Quoted 2 lines
2.51.0
The fix looks good to me.
The following commit has been merged into the timers/urgent branch of tip:
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: c7418164b463056bf4327b6a2abe638b78250f13 Gitweb: https://git.kernel.org/tip/c7418164b463056bf4327b6a2abe638b78250f13 Author: Dan Carpenter <[email protected]> AuthorDate: Tue, 25 Nov 2025 16:55:19 +03:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 25 Nov 2025 17:52:24 +01:00
timekeeping: Fix error code in tk_aux_sysfs_init()
If kobject_create_and_add() fails on the first iteration, then the error code is set to -ENOMEM which is correct. But if it fails in subsequent iterations then "ret" is zero, which means success, but it should be -ENOMEM.
Set the error code to -ENOMEM correctly.
--- kernel/time/timekeeping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/time/timekeeping.c +3 -1
@@ -3073,8 +3073,10 @@ static int __init tk_aux_sysfs_init(void)char id[2 ] = { [0 ] ='0' + i, };struct kobject *clk =kobject_create_and_add (id, auxo); -if (!clk) +if (!clk) { + ret = -ENOMEM ; goto err_clean; + } ret =sysfs_create_group (clk, &aux_clock_enable_attr_group);if (ret)