From: Suyuan Wang Date: Sun, 22 Nov 2026 11:55:28 +0000 Subject: [PATCH 3/3] cpufreq: s5pv210: Fix resource leaks on probe error paths MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261122-cpufreq-leaks-v1-3-96fc17ff7339@gmail.com> References: <20261122-cpufreq-leaks-v1-0-96fc17ff7339@gmail.com> In-Reply-To: <20261122-cpufreq-leaks-v1-0-96fc17ff7339@gmail.com> To: rafael@kernel.org, viresh.kumar@linaro.org, krzk@kernel.org, peter.griffin@linaro.org Cc: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, alim.akhtar@samsung.com, linux-kernel@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795348526; l=2583; i=shyckless@gmail.com; s=default; h=from:subject:message-id; bh=u26GdNff9h8VDqjlemiKXHAuftopncbeRgVHJ/CpuKU=; b=CrzgHHiglo92NWgPpcnitjmDoIyGezX87Do2D12VT7kp6fyLOS0r3fq5gaaTll/JBZKRugRX3 f5B2+44sqakD6BU6xI6LbdUulZpWYly5wOr4asrOv6uJ/lgLavdA7fG X-Developer-Key: i=shyckless@gmail.com; a=ed25519; pk=pMtccVGiWES3bV+7YBFuBclkvq2n2HBHQ5azaBrK2lY= X-Endpoint-Received: by B4 Relay for shyckless@gmail.com/default with auth_id=1498 List-Id: B4 Relay Submissions From: Suyuan Wang 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 Signed-off-by: Kaixuan Li Signed-off-by: Suyuan Wang --- 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