mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] clocksource/drivers/timer-fsl-ftm: Fix clk reference leak in error paths
@ 2026-09-15  5:02 Wentao Liang
  2026-09-21 15:32 ` krzk
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-15  5:02 UTC (permalink / raw)
  To: Li.Xiubo; +Cc: daniel.lezcano, linux-kernel, tglx, lkml, Wentao Liang, stable

__ftm_clk_init() obtains clock references with of_clk_get_by_name() but
never releases them on the error paths. If clk_prepare_enable() fails on
the counter clock, the reference is leaked. The second of_clk_get_by_name()
also overwrites the first clk pointer, so a failure to get or prepare the
ftm clock loses the counter clock reference as well; on the get failure
path the counter clock is left enabled and unreferenced.

Release the references on the error paths: clk_put() when prepare+enable
fails, and clk_disable_unprepare() followed by clk_put() when aborting
after the counter clock has been enabled. The clocks intentionally stay
enabled on the success path, so those are left untouched.

Fixes: 2529c3a33079 ("clocksource: Add Freescale FlexTimer Module (FTM) timer support")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/clocksource/timer-fsl-ftm.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/timer-fsl-ftm.c b/drivers/clocksource/timer-fsl-ftm.c
index 4eed6cb46132..8ada0c3e088a 100644
--- a/drivers/clocksource/timer-fsl-ftm.c
+++ b/drivers/clocksource/timer-fsl-ftm.c
@@ -230,7 +230,8 @@ static int __init ftm_clocksource_init(unsigned long freq)
 static int __init __ftm_clk_init(struct device_node *np, char *cnt_name,
 				 char *ftm_name)
 {
-	struct clk *clk;
+	struct clk *clk, *ftm_clk;
+	unsigned long rate;
 	int err;
 
 	clk = of_clk_get_by_name(np, cnt_name);
@@ -242,20 +243,28 @@ static int __init __ftm_clk_init(struct device_node *np, char *cnt_name,
 	if (err) {
 		pr_err("ftm: clock failed to prepare+enable \"%s\": %d\n",
 			cnt_name, err);
+		clk_put(clk);
 		return err;
 	}
 
-	clk = of_clk_get_by_name(np, ftm_name);
-	if (IS_ERR(clk)) {
-		pr_err("ftm: Cannot get \"%s\": %ld\n", ftm_name, PTR_ERR(clk));
-		return PTR_ERR(clk);
+	ftm_clk = of_clk_get_by_name(np, ftm_name);
+	if (IS_ERR(ftm_clk)) {
+		pr_err("ftm: Cannot get \"%s\": %ld\n", ftm_name,
+			PTR_ERR(ftm_clk));
+		clk_disable_unprepare(clk);
+		clk_put(clk);
+		return PTR_ERR(ftm_clk);
 	}
-	err = clk_prepare_enable(clk);
-	if (err)
+	err = clk_prepare_enable(ftm_clk);
+	if (err) {
 		pr_err("ftm: clock failed to prepare+enable \"%s\": %d\n",
 			ftm_name, err);
+		rate = clk_get_rate(ftm_clk);
+		clk_put(ftm_clk);
+		return rate;
+	}
 
-	return clk_get_rate(clk);
+	return clk_get_rate(ftm_clk);
 }
 
 static unsigned long __init ftm_clk_init(struct device_node *np)
-- 
2.34.1


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

* Re: [PATCH] clocksource/drivers/timer-fsl-ftm: Fix clk reference leak in error paths
  2026-09-15  5:02 [PATCH] clocksource/drivers/timer-fsl-ftm: Fix clk reference leak in error paths Wentao Liang
@ 2026-09-21 15:32 ` krzk
  0 siblings, 0 replies; 2+ messages in thread
From: krzk @ 2026-09-21 15:32 UTC (permalink / raw)
  To: Wentao Liang; +Cc: stable, linux-kernel, daniel.lezcano, Li.Xiubo, tglx, lkml


On Tue, 15 Sep 2026 05:02:58 +0000, Wentao Liang wrote:
> __ftm_clk_init() obtains clock references with of_clk_get_by_name() but
> never releases them on the error paths. If clk_prepare_enable() fails on
> the counter clock, the reference is leaked. The second of_clk_get_by_name()
> also overwrites the first clk pointer, so a failure to get or prepare the
> ftm clock loses the counter clock reference as well; on the get failure
> path the counter clock is left enabled and unreferenced.
> 
> Release the references on the error paths: clk_put() when prepare+enable
> fails, and clk_disable_unprepare() followed by clk_put() when aborting
> after the counter clock has been enabled. The clocks intentionally stay
> enabled on the success path, so those are left untouched.
> 
> Fixes: 2529c3a33079 ("clocksource: Add Freescale FlexTimer Module (FTM) timer support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/clocksource/timer-fsl-ftm.c | 25 +++++++++++++++++--------
>  1 file changed, 17 insertions(+), 8 deletions(-)
> 


You sent multiple independent patches, to multiple independent
subsystems. The amount of these patches clearly suggest this was
AI generated and most likely not tested.

More importantly, you sent all this work without properly organizing
relevant patches into patchsets. This makes reviewing difficult
and might cause multiple reviewers to address the same issue.
Replying to the entire set is impossible and requires handling each
patch independently, instead of applying or discarding the set.
Maintainers also won't see the bigger picture of your work. Quite
worrying.

This is on the verge of hostile patch: bomb us with so many
contributions, we won't be able to handle them in efficient manner,
like responding ONCE to ask you to slow down.  Considering all this
is untested and LLM generated, I have even more doubts whether this
should be considered for review.

Please read kernel documentation BEFORE posting more work. It will
explain you how to identify subsystems, how to organize your work per
subsystem, how to document usage of LLM and how what you should not
do if this was posted in a good faith.

Best regards,
Krzysztof




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

end of thread, other threads:[~2026-09-21 15:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15  5:02 [PATCH] clocksource/drivers/timer-fsl-ftm: Fix clk reference leak in error paths Wentao Liang
2026-09-21 15:32 ` krzk

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

all inboxes | Powered by JetHome®