[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251126074559.1709-1-vulab@iscas.ac.cn>
Date: Wed, 26 Nov 2025 15:45:59 +0800
From: Haotian Zhang <vulab@...as.ac.cn>
To: Michal Simek <michal.simek@....com>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Thomas Gleixner <tglx@...utronix.de>
Cc: linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Haotian Zhang <vulab@...as.ac.cn>
Subject: [PATCH] clocksource: timer-cadence-ttc: Fix resource leaks in error paths
The ttc_setup_clocksource() and ttc_setup_clockevent() fail to
unregister the clock notifier in their error paths, potentially
leading to a resource leak. Additionally, ttc_setup_clocksource()
leaks the prepared clock reference upon failure.
Unregister the clock notifier and disable the clock in the
error path of ttc_setup_clocksource(). Also, add the missing
clock notifier unregistration in the error path of
ttc_setup_clockevent() to ensure proper cleanup.
Fixes: e932900a3279 ("arm: zynq: Use standard timer binding")
Fixes: 91dc985c5e51 ("ARM: zynq: add clk binding support to the ttc")
Signed-off-by: Haotian Zhang <vulab@...as.ac.cn>
---
drivers/clocksource/timer-cadence-ttc.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c
index b8a1cf59b9d6..70384faad66d 100644
--- a/drivers/clocksource/timer-cadence-ttc.c
+++ b/drivers/clocksource/timer-cadence-ttc.c
@@ -333,6 +333,7 @@ static int __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
{
struct ttc_timer_clocksource *ttccs;
int err;
+ bool notifier_registered = false;
ttccs = kzalloc(sizeof(*ttccs), GFP_KERNEL);
if (!ttccs)
@@ -356,6 +357,8 @@ static int __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
&ttccs->ttc.clk_rate_change_nb);
if (err)
pr_warn("Unable to register clock notifier.\n");
+ else
+ notifier_registered = true;
ttccs->ttc.base_addr = base;
ttccs->cs.name = "ttc_clocksource";
@@ -377,6 +380,10 @@ static int __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
err = clocksource_register_hz(&ttccs->cs, ttccs->ttc.freq / PRESCALE);
if (err) {
+ if (notifier_registered)
+ clk_notifier_unregister(ttccs->ttc.clk,
+ &ttccs->ttc.clk_rate_change_nb);
+ clk_disable_unprepare(ttccs->ttc.clk);
kfree(ttccs);
return err;
}
@@ -465,13 +472,16 @@ static int __init ttc_setup_clockevent(struct clk *clk,
err = request_irq(irq, ttc_clock_event_interrupt,
IRQF_TIMER, ttcce->ce.name, ttcce);
if (err)
- goto out_clk_unprepare;
+ goto out_clk_notifier_unregister;
clockevents_config_and_register(&ttcce->ce,
ttcce->ttc.freq / PRESCALE, 1, 0xfffe);
return 0;
+out_clk_notifier_unregister:
+ clk_notifier_unregister(ttcce->ttc.clk,
+ &ttcce->ttc.clk_rate_change_nb);
out_clk_unprepare:
clk_disable_unprepare(ttcce->ttc.clk);
out_kfree:
--
2.50.1.windows.1
Powered by blists - more mailing lists