The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] timekeeping: Fix error code in tk_aux_sysfs_init()
@ 2025-11-25 13:55 Dan Carpenter
  2025-11-25 14:17 ` Malaya Kumar Rout
  2025-11-25 16:56 ` [tip: timers/urgent] " tip-bot2 for Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-11-25 13:55 UTC (permalink / raw)
  To: Malaya Kumar Rout
  Cc: John Stultz, Thomas Gleixner, Stephen Boyd, linux-kernel,
	kernel-janitors

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.

Fixes: 7b5ab04f035f ("timekeeping: Fix resource leak in tk_aux_sysfs_init() error paths")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 kernel/time/timekeeping.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 0c8b77ee4a3a..3ec3daa4acab 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -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)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] timekeeping: Fix error code in tk_aux_sysfs_init()
  2025-11-25 13:55 [PATCH] timekeeping: Fix error code in tk_aux_sysfs_init() Dan Carpenter
@ 2025-11-25 14:17 ` Malaya Kumar Rout
  2025-11-25 16:56 ` [tip: timers/urgent] " tip-bot2 for Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Malaya Kumar Rout @ 2025-11-25 14:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: John Stultz, Thomas Gleixner, Stephen Boyd, linux-kernel,
	kernel-janitors

On Tue, Nov 25, 2025 at 7:25 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> 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.
>
> Fixes: 7b5ab04f035f ("timekeeping: Fix resource leak in tk_aux_sysfs_init() error paths")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  kernel/time/timekeeping.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index 0c8b77ee4a3a..3ec3daa4acab 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -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)
> --
> 2.51.0
>
The fix looks good to me.

Reviewed-by: Malaya Kumar Rout <mrout@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: timers/urgent] timekeeping: Fix error code in tk_aux_sysfs_init()
  2025-11-25 13:55 [PATCH] timekeeping: Fix error code in tk_aux_sysfs_init() Dan Carpenter
  2025-11-25 14:17 ` Malaya Kumar Rout
@ 2025-11-25 16:56 ` tip-bot2 for Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Dan Carpenter @ 2025-11-25 16:56 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Dan Carpenter, Thomas Gleixner, Malaya Kumar Rout, x86,
	linux-kernel

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 <dan.carpenter@linaro.org>
AuthorDate:    Tue, 25 Nov 2025 16:55:19 +03:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
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.

Fixes: 7b5ab04f035f ("timekeeping: Fix resource leak in tk_aux_sysfs_init() error paths")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Malaya Kumar Rout <mrout@redhat.com>
Link: https://patch.msgid.link/aSW1R8q5zoY_DgQE@stanley.mountain
---
 kernel/time/timekeeping.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 08e0943..4790da8 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -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)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-25 16:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-25 13:55 [PATCH] timekeeping: Fix error code in tk_aux_sysfs_init() Dan Carpenter
2025-11-25 14:17 ` Malaya Kumar Rout
2025-11-25 16:56 ` [tip: timers/urgent] " tip-bot2 for Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox