From: Haotian Zhang <vulab@iscas.ac.cn>
To: Michal Simek <michal.simek@amd.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Haotian Zhang <vulab@iscas.ac.cn>
Subject: [PATCH] clocksource: timer-cadence-ttc: Fix resource leaks in error paths
Date: Wed, 26 Nov 2025 15:45:59 +0800 [thread overview]
Message-ID: <20251126074559.1709-1-vulab@iscas.ac.cn> (raw)
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@iscas.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
next reply other threads:[~2025-11-26 7:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 7:45 Haotian Zhang [this message]
2025-11-26 10:34 ` Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251126074559.1709-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=daniel.lezcano@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®