Skip to contentSkip to conversation

clocksource/drivers/timer-econet-en751221: Fix clock reference leak

PATCH Applied Wentao Liang 3 participants 3 messages Sep 15 – Oct 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource/drivers/timer-econet-en751221: Fix clock reference leak

timer_init() obtains the timer clock with of_clk_get() and only reads its frequency with clk_get_rate(); the clock is never prepared nor enabled. All four return paths after the acquisition (of_iomap() failure, clocksource_mmio_init() failure, cevt_init() failure and success) return without clk_put(), leaking the consumer reference.

Drop the reference with clk_put() right after the frequency has been read. The clock enable state is untouched.

Fixes 3b4c33ac87d0 ("clocksource/drivers: Add EcoNet Timer HPT driver")
---
 drivers/clocksource/timer-econet-en751221.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-econet-en751221.c +1 -0
index 4008076b1a21..1859335345b5 100644
@@ -181,6 +181,7 @@ static int __init timer_init(struct device_node *np)
 	}
 
 	econet_timer.freq_hz = clk_get_rate(clk);
+	clk_put(clk);
 
 	for (int i = 0; i < num_blocks; i++) {
 		econet_timer.membase[i] = of_iomap(np, i);
Signature · 1 line
2.34.1
maintainer Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Wentao Liang

timer_init() obtains the timer clock with of_clk_get() and only reads its frequency with clk_get_rate(); the clock is never prepared nor enabled. All four return paths after the acquisition (of_iomap() failure, clocksource_mmio_init() failure, cevt_init() failure and success) return without clk_put(), leaking the consumer reference.

Drop the reference with clk_put() right after the frequency has been read. The clock enable state is untouched.

Fixes 3b4c33ac87d0 ("clocksource/drivers: Add EcoNet Timer HPT driver")
Quoted 16 lines
---
  drivers/clocksource/timer-econet-en751221.c | 1 +
  1 file changed, 1 insertion(+)
drivers/clocksource/timer-econet-en751221.c +1 -0
index 4008076b1a21..1859335345b5 100644
@@ -181,6 +181,7 @@ static int __init timer_init(struct device_node *np)
  	}
 
  	econet_timer.freq_hz = clk_get_rate(clk);
+	clk_put(clk);
 
  	for (int i = 0; i < num_blocks; i++) {
  		econet_timer.membase[i] = of_iomap(np, i);
#2 lore raw
In reply to Wentao Liang
The following commit has been merged into the timers/drivers/next branch of clocksource:

The following commit has been merged into the timers/drivers/next branch of clocksource:

Commit-ID:     36790ef57803400339d8ea4081d85483264dbd6c
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/daniel.lezcano/linux.git//36790ef57803400339d8ea4081d85483264dbd6c
Author:        Wentao Liang <[email protected]>
AuthorDate:    Tue, 15 Sep 2026 05:45:52 
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Wed, 07 Oct 2026 15:46:14 +02:00

clocksource/drivers/timer-econet-en751221: Fix clock reference leak

timer_init() obtains the timer clock with of_clk_get() and only reads its frequency with clk_get_rate(); the clock is never prepared nor enabled. All four return paths after the acquisition (of_iomap() failure, clocksource_mmio_init() failure, cevt_init() failure and success) return without clk_put(), leaking the consumer reference.

Drop the reference with clk_put() right after the frequency has been read. The clock enable state is untouched.

Fixes 3b4c33ac87d0 ("clocksource/drivers: Add EcoNet Timer HPT driver")
---
 drivers/clocksource/timer-econet-en751221.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-econet-en751221.c +1 -0
index 4008076..1859335 100644
@@ -181,6 +181,7 @@ static int __init timer_init(struct device_node *np)
 	}
 
 	econet_timer.freq_hz = clk_get_rate(clk);
+	clk_put(clk);
 
 	for (int i = 0; i < num_blocks; i++) {
 		econet_timer.membase[i] = of_iomap(np, i);