[PATCH v2 1/2] cpufreq: s5pv210: Release resources on platform removal

Tian Xuechen 202300460064 at mail.sdu.edu.cn
Mon Nov 30 00:27:50 PST 2026


From: Tian Xuechen <202300460064 at mail.sdu.edu.cn>

Unbinding the S5PV210 platform driver leaves its reboot notifier and
cpufreq driver registered. It also retains references to the policy
clocks, the two regulators and the clock and DMC register mappings.

Unregister the reboot notifier first because its callback can use the
cpufreq policy. Then unregister the cpufreq driver and release the
register mappings and regulators. Add a policy exit callback to drop
the clock references acquired by s5pv210_cpu_init().

This issue was found by our static analysis tool under development.

Fixes: 6d4ed0f46af6 ("cpufreq: s5pv210: Make the driver multiplatform aware")
Signed-off-by: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
---
 drivers/cpufreq/s5pv210-cpufreq.c | 39 +++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
index 29b1c5d71a8b..a5b4f1342d5a 100644
--- a/drivers/cpufreq/s5pv210-cpufreq.c
+++ b/drivers/cpufreq/s5pv210-cpufreq.c
@@ -553,6 +553,13 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
 	return ret;
 }
 
+static void s5pv210_cpu_exit(struct cpufreq_policy *policy)
+{
+	clk_put(dmc1_clk);
+	clk_put(dmc0_clk);
+	clk_put(policy->clk);
+}
+
 static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
 						 unsigned long event, void *ptr)
 {
@@ -579,6 +586,7 @@ static struct cpufreq_driver s5pv210_driver = {
 	.target_index	= s5pv210_target,
 	.get		= cpufreq_generic_get,
 	.init		= s5pv210_cpu_init,
+	.exit		= s5pv210_cpu_exit,
 	.name		= "s5pv210",
 	.suspend	= cpufreq_generic_suspend,
 	.resume		= cpufreq_generic_suspend, /* We need to set SLEEP FREQ again */
@@ -588,6 +596,19 @@ static struct notifier_block s5pv210_cpufreq_reboot_notifier = {
 	.notifier_call = s5pv210_cpufreq_reboot_notifier_event,
 };
 
+static void s5pv210_unmap_registers(void)
+{
+	unsigned int id;
+
+	for (id = 0; id < ARRAY_SIZE(dmc_base); ++id)
+		if (dmc_base[id]) {
+			iounmap(dmc_base[id]);
+			dmc_base[id] = NULL;
+		}
+
+	iounmap(clk_base);
+}
+
 static int s5pv210_cpufreq_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -665,13 +686,7 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
 	unregister_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
 
 err_dmc:
-	for (id = 0; id < ARRAY_SIZE(dmc_base); ++id)
-		if (dmc_base[id]) {
-			iounmap(dmc_base[id]);
-			dmc_base[id] = NULL;
-		}
-
-	iounmap(clk_base);
+	s5pv210_unmap_registers();
 
 err_clock:
 	regulator_put(int_regulator);
@@ -682,10 +697,20 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
 	return result;
 }
 
+static void s5pv210_cpufreq_remove(struct platform_device *pdev)
+{
+	unregister_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
+	cpufreq_unregister_driver(&s5pv210_driver);
+	s5pv210_unmap_registers();
+	regulator_put(int_regulator);
+	regulator_put(arm_regulator);
+}
+
 static struct platform_driver s5pv210_cpufreq_platdrv = {
 	.driver = {
 		.name	= "s5pv210-cpufreq",
 	},
 	.probe = s5pv210_cpufreq_probe,
+	.remove = s5pv210_cpufreq_remove,
 };
 builtin_platform_driver(s5pv210_cpufreq_platdrv);



More information about the linux-arm-kernel mailing list