[PATCH 3/6] clocksource/drivers/timer-npcm7xx: Fix clock reference leak in npcm7xx_timer_init

From: Wentao Liang

Date: Tue Sep 15 2026 - 01:20:36 EST


npcm7xx_timer_init() looks up the optional timer 1 clock with
of_clk_get(), which takes a reference on the clock, and prepares and
enables it. The clock is meant to stay enabled, but the local clk
pointer is lost when the function returns and clk_put() is never
called, leaking the consumer reference on every boot when the timer 1
clock is present in the device tree.

Drop the reference with clk_put() right after the clock has been
prepared and enabled; this keeps the clock running while releasing the
reference.

Fixes: db78539fc95c ("clocksource/drivers/timer-npcm7xx: Enable timer 1 clock before use")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/clocksource/timer-npcm7xx.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/timer-npcm7xx.c b/drivers/clocksource/timer-npcm7xx.c
index 9af30af5f989..1ac6424fe879 100644
--- a/drivers/clocksource/timer-npcm7xx.c
+++ b/drivers/clocksource/timer-npcm7xx.c
@@ -203,10 +203,12 @@ static int __init npcm7xx_timer_init(struct device_node *np)
/* Enable the clock for timer1, if it exists */
clk = of_clk_get(np, 1);
if (clk) {
- if (!IS_ERR(clk))
+ if (!IS_ERR(clk)) {
clk_prepare_enable(clk);
- else
+ clk_put(clk);
+ } else {
pr_warn("%pOF: Failed to get clock for timer1: %pe", np, clk);
+ }
}

npcm7xx_clocksource_init();
--
2.34.1