[PATCH 1/2] cpufreq: s5pv210: Add teardown and unwind probe failures
Zhongqiu Han
zhongqiu.han at oss.qualcomm.com
Sun Nov 29 06:07:46 PST 2026
On 11/27/2026 7:33 PM, Tian Xuechen wrote:
> From: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
>
> Platform unbind leaves the cpufreq driver and reboot notifier registered
> and retains the clocks, regulators and register mappings. A failed
> registration also bypasses probe cleanup.
>
> Register the reboot notifier after the cpufreq driver and unwind both in
> reverse order. Drop the policy clocks on policy exit and release the
> register mappings and regulators on failure and removal.
>
> This issue was found by our static analysis tool under development.
The probe error path part of this patch is already fixed by commit
5850b6ad8f16 ("cpufreq: s5pv210: Fix resource leaks on probe error
paths") in tree (git://git.kernel.org/pub/scm/linux/kernel/git/vireshk
pm.git cpufreq/arm/linux-next). Could you please rebase onto that branch
and keep only the remaining changes in v2?
>
> 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 | 52 ++++++++++++++++++++++++-------
> 1 file changed, 40 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
> index e64e84e1ee79..b01b77564ff8 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,17 @@ 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) {
> + 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;
> @@ -633,8 +652,8 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
> id = of_alias_get_id(dmc, "dmc");
> 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;
> + result = id < 0 ? id : -EINVAL;
> + goto err_dmc;
> }
>
> dmc_base[id] = of_iomap(dmc, 0);
> @@ -653,19 +672,18 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
> }
> }
>
> - register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
> + result = cpufreq_register_driver(&s5pv210_driver);
> + if (result)
> + goto err_dmc;
>
> - return cpufreq_register_driver(&s5pv210_driver);
> + result = register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
> + if (!result)
> + return 0;
>
> -err_dmc:
> - for (id = 0; id < ARRAY_SIZE(dmc_base); ++id)
> - if (dmc_base[id]) {
> - iounmap(dmc_base[id]);
> - dmc_base[id] = NULL;
> - }
> + cpufreq_unregister_driver(&s5pv210_driver);
>
> -err_clk_base:
> - iounmap(clk_base);
> +err_dmc:
> + s5pv210_unmap_registers();
>
> err_clock:
> regulator_put(int_regulator);
> @@ -676,10 +694,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);
>
--
Thx and BRs,
Zhongqiu Han
More information about the linux-arm-kernel
mailing list