Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] cpufreq: Fix leaks on probe error paths in three drivers
@ 2026-11-22 11:55 Suyuan Wang via B4 Relay
  2026-11-22 11:55 ` [PATCH 1/3] cpufreq: highbank: Put cpu clock if clk notifier registration fails Suyuan Wang via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-22 11:55 UTC (permalink / raw)
  To: rafael, viresh.kumar, krzk, peter.griffin
  Cc: linux-samsung-soc, linux-arm-kernel, linux-pm, alim.akhtar,
	linux-kernel

Three small fixes for resources that are not released when a cpufreq
driver fails to probe: the cpu clock in highbank, the three clocks in
kirkwood (also on unbind), and the regulators and register mappings in
s5pv210, and its reboot notifier, when cpufreq_register_driver() fails.

Found with a static analysis tool and checked by hand. Compile tested
on arm (W=1, multi_v5 for kirkwood); I don't have the hardware.

---
Suyuan Wang (3):
      cpufreq: highbank: Put cpu clock if clk notifier registration fails
      cpufreq: kirkwood: Put clocks on error and in remove
      cpufreq: s5pv210: Fix resource leaks on probe error paths

 drivers/cpufreq/highbank-cpufreq.c |  1 +
 drivers/cpufreq/kirkwood-cpufreq.c | 15 ++++++++++++---
 drivers/cpufreq/s5pv210-cpufreq.c  | 12 +++++++++---
 3 files changed, 22 insertions(+), 6 deletions(-)




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

* [PATCH 1/3] cpufreq: highbank: Put cpu clock if clk notifier registration fails
  2026-11-22 11:55 [PATCH 0/3] cpufreq: Fix leaks on probe error paths in three drivers Suyuan Wang via B4 Relay
@ 2026-11-22 11:55 ` Suyuan Wang via B4 Relay
  2026-11-22 11:55 ` [PATCH 2/3] cpufreq: kirkwood: Put clocks on error and in remove Suyuan Wang via B4 Relay
  2026-11-22 11:55 ` [PATCH 3/3] cpufreq: s5pv210: Fix resource leaks on probe error paths Suyuan Wang via B4 Relay
  2 siblings, 0 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-22 11:55 UTC (permalink / raw)
  To: rafael, viresh.kumar, krzk, peter.griffin
  Cc: linux-samsung-soc, linux-arm-kernel, linux-pm, alim.akhtar,
	linux-kernel

From: Suyuan Wang <stevewong@hust.edu.cn>

hb_cpufreq_driver_init() gets the cpu0 clock with clk_get() and then
registers a clk notifier on it. If clk_notifier_register() fails, the
function jumps to out_put_node and returns the error, but the clock
reference is never dropped.

Call clk_put() on that error path.

Found with a static analysis tool and checked by hand.

Fixes: 6754f556103b ("cpufreq / highbank: add support for highbank cpufreq")
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
 drivers/cpufreq/highbank-cpufreq.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/cpufreq/highbank-cpufreq.c b/drivers/cpufreq/highbank-cpufreq.c
index a45864701143..ccdaff4384d2 100644
--- a/drivers/cpufreq/highbank-cpufreq.c
+++ b/drivers/cpufreq/highbank-cpufreq.c
@@ -89,6 +89,7 @@ static int __init hb_cpufreq_driver_init(void)
 	ret = clk_notifier_register(cpu_clk, &hb_cpufreq_clk_nb);
 	if (ret) {
 		pr_err("failed to register clk notifier: %d\n", ret);
+		clk_put(cpu_clk);
 		goto out_put_node;
 	}
 

-- 
2.34.1




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

* [PATCH 2/3] cpufreq: kirkwood: Put clocks on error and in remove
  2026-11-22 11:55 [PATCH 0/3] cpufreq: Fix leaks on probe error paths in three drivers Suyuan Wang via B4 Relay
  2026-11-22 11:55 ` [PATCH 1/3] cpufreq: highbank: Put cpu clock if clk notifier registration fails Suyuan Wang via B4 Relay
@ 2026-11-22 11:55 ` Suyuan Wang via B4 Relay
  2026-11-22 11:55 ` [PATCH 3/3] cpufreq: s5pv210: Fix resource leaks on probe error paths Suyuan Wang via B4 Relay
  2 siblings, 0 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-22 11:55 UTC (permalink / raw)
  To: rafael, viresh.kumar, krzk, peter.griffin
  Cc: linux-samsung-soc, linux-arm-kernel, linux-pm, alim.akhtar,
	linux-kernel

From: Suyuan Wang <stevewong@hust.edu.cn>

kirkwood_cpufreq_probe() gets three clocks with of_clk_get_by_name():
cpu_clk, ddrclk and powersave. None of them is ever released with
clk_put(). The error paths only disable and unprepare the clocks, and
kirkwood_cpufreq_remove() does the same. So the clock references leak
when probe fails (for example on -EPROBE_DEFER) and on every unbind.

Add the missing clk_put() calls to the error paths and to remove. The
"Unable to prepare" paths now jump to new labels that only put the clock
that failed to enable.

Found with a static analysis tool and checked by hand.

Fixes: 2a4bd9f0db24 ("cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs")
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
 drivers/cpufreq/kirkwood-cpufreq.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
index 24b285cbeb8d..e85658081c07 100644
--- a/drivers/cpufreq/kirkwood-cpufreq.c
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -125,7 +125,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
 	err = clk_prepare_enable(priv.cpu_clk);
 	if (err) {
 		dev_err(priv.dev, "Unable to prepare cpuclk\n");
-		goto out_node;
+		goto out_put_cpu;
 	}
 
 	kirkwood_freq_table[0].frequency = clk_get_rate(priv.cpu_clk) / 1000;
@@ -140,7 +140,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
 	err = clk_prepare_enable(priv.ddr_clk);
 	if (err) {
 		dev_err(priv.dev, "Unable to prepare ddrclk\n");
-		goto out_cpu;
+		goto out_put_ddr;
 	}
 	kirkwood_freq_table[1].frequency = clk_get_rate(priv.ddr_clk) / 1000;
 
@@ -153,7 +153,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
 	err = clk_prepare_enable(priv.powersave_clk);
 	if (err) {
 		dev_err(priv.dev, "Unable to prepare powersave clk\n");
-		goto out_ddr;
+		goto out_put_powersave;
 	}
 
 	err = cpufreq_register_driver(&kirkwood_cpufreq_driver);
@@ -167,10 +167,16 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
 
 out_powersave:
 	clk_disable_unprepare(priv.powersave_clk);
+out_put_powersave:
+	clk_put(priv.powersave_clk);
 out_ddr:
 	clk_disable_unprepare(priv.ddr_clk);
+out_put_ddr:
+	clk_put(priv.ddr_clk);
 out_cpu:
 	clk_disable_unprepare(priv.cpu_clk);
+out_put_cpu:
+	clk_put(priv.cpu_clk);
 out_node:
 	of_node_put(np);
 
@@ -182,8 +188,11 @@ static void kirkwood_cpufreq_remove(struct platform_device *pdev)
 	cpufreq_unregister_driver(&kirkwood_cpufreq_driver);
 
 	clk_disable_unprepare(priv.powersave_clk);
+	clk_put(priv.powersave_clk);
 	clk_disable_unprepare(priv.ddr_clk);
+	clk_put(priv.ddr_clk);
 	clk_disable_unprepare(priv.cpu_clk);
+	clk_put(priv.cpu_clk);
 }
 
 static struct platform_driver kirkwood_cpufreq_platform_driver = {

-- 
2.34.1




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

* [PATCH 3/3] cpufreq: s5pv210: Fix resource leaks on probe error paths
  2026-11-22 11:55 [PATCH 0/3] cpufreq: Fix leaks on probe error paths in three drivers Suyuan Wang via B4 Relay
  2026-11-22 11:55 ` [PATCH 1/3] cpufreq: highbank: Put cpu clock if clk notifier registration fails Suyuan Wang via B4 Relay
  2026-11-22 11:55 ` [PATCH 2/3] cpufreq: kirkwood: Put clocks on error and in remove Suyuan Wang via B4 Relay
@ 2026-11-22 11:55 ` Suyuan Wang via B4 Relay
  2 siblings, 0 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-22 11:55 UTC (permalink / raw)
  To: rafael, viresh.kumar, krzk, peter.griffin
  Cc: linux-samsung-soc, linux-arm-kernel, linux-pm, alim.akhtar,
	linux-kernel

From: Suyuan Wang <stevewong@hust.edu.cn>

s5pv210_cpufreq_probe() returns the result of cpufreq_register_driver()
directly:

	register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);

	return cpufreq_register_driver(&s5pv210_driver);

If the registration fails, for example because s5pv210_cpu_init()
fails, the resources taken by the probe itself are leaked: the two
regulators and the clock and DMC register mappings. The reboot notifier
also stays registered. (s5pv210_cpu_init() releases its own clocks on
its error paths, and the cpufreq core tears down its own state.)

Also, when a DMC node has a bad alias, the code jumps to err_clk_base
and skips unmapping DMC registers that were already mapped for an
earlier node.

Unregister the reboot notifier and go through the existing unwind code
when cpufreq_register_driver() fails, and jump to err_dmc on the alias
error. The err_clk_base label has no users after this, so drop it.

Found with a static analysis tool and checked by hand.

Fixes: 6d4ed0f46af6 ("cpufreq: s5pv210: Make the driver multiplatform aware")
Fixes: e0e5b2b4f427 ("cpufreq: s5pv210: Defer probe if getting regulators fail")
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
 drivers/cpufreq/s5pv210-cpufreq.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
index e64e84e1ee79..29b1c5d71a8b 100644
--- a/drivers/cpufreq/s5pv210-cpufreq.c
+++ b/drivers/cpufreq/s5pv210-cpufreq.c
@@ -634,7 +634,7 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
 		if (id < 0 || id >= ARRAY_SIZE(dmc_base)) {
 			dev_err(dev, "failed to get alias of dmc node '%pOFn'\n", dmc);
 			result = id;
-			goto err_clk_base;
+			goto err_dmc;
 		}
 
 		dmc_base[id] = of_iomap(dmc, 0);
@@ -655,7 +655,14 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
 
 	register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
 
-	return cpufreq_register_driver(&s5pv210_driver);
+	result = cpufreq_register_driver(&s5pv210_driver);
+	if (result)
+		goto err_reboot_notifier;
+
+	return 0;
+
+err_reboot_notifier:
+	unregister_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
 
 err_dmc:
 	for (id = 0; id < ARRAY_SIZE(dmc_base); ++id)
@@ -664,7 +671,6 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
 			dmc_base[id] = NULL;
 		}
 
-err_clk_base:
 	iounmap(clk_base);
 
 err_clock:

-- 
2.34.1




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

end of thread, other threads:[~2026-11-22 11:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 11:55 [PATCH 0/3] cpufreq: Fix leaks on probe error paths in three drivers Suyuan Wang via B4 Relay
2026-11-22 11:55 ` [PATCH 1/3] cpufreq: highbank: Put cpu clock if clk notifier registration fails Suyuan Wang via B4 Relay
2026-11-22 11:55 ` [PATCH 2/3] cpufreq: kirkwood: Put clocks on error and in remove Suyuan Wang via B4 Relay
2026-11-22 11:55 ` [PATCH 3/3] cpufreq: s5pv210: Fix resource leaks on probe error paths Suyuan Wang via B4 Relay

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