Skip to contentSkip to conversation

cpufreq: mediatek: fix device leak on probe failure

PATCH Applied Johan Hovold 4 participants 6 messages Sep 9, 2025 – Sep 29, 2025

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

PATCH 1/1 cpufreq: mediatek: fix device leak on probe failure

Make sure to drop the reference to the cci device taken by of_find_device_by_node() on probe failure (e.g. probe deferral).

Fixes 0daa47325bae ("cpufreq: mediatek: Link CCI device to CPU")
Cc Jia-Wei Chang <[email protected]>
Cc Rex-BC Chen <[email protected]>
---
 drivers/cpufreq/mediatek-cpufreq.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/cpufreq/mediatek-cpufreq.c +11 -3
index f3f02c4b6888..21537a05785d 100644
@@ -404,9 +404,11 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
 	}
 
 	info->cpu_clk = clk_get(cpu_dev, "cpu");
-	if (IS_ERR(info->cpu_clk))
-		return dev_err_probe(cpu_dev, PTR_ERR(info->cpu_clk),
-				     "cpu%d: failed to get cpu clk\n", cpu);
+	if (IS_ERR(info->cpu_clk)) {
+		ret = PTR_ERR(info->cpu_clk);
+		dev_err_probe(cpu_dev, ret, "cpu%d: failed to get cpu clk\n", cpu);
+		goto out_put_cci_dev;
+	}
 
 	info->inter_clk = clk_get(cpu_dev, "intermediate");
 	if (IS_ERR(info->inter_clk)) {
@@ -552,6 +554,10 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
 out_free_mux_clock:
 	clk_put(info->cpu_clk);
 
+out_put_cci_dev:
+	if (info->soc_data->ccifreq_supported)
+		put_device(info->cci_dev);
+
 	return ret;
 }
 
@@ -569,6 +575,8 @@ static void mtk_cpu_dvfs_info_release(struct mtk_cpu_dvfs_info *info)
 	clk_put(info->inter_clk);
 	dev_pm_opp_of_cpumask_remove_table(&info->cpus);
 	dev_pm_opp_unregister_notifier(info->cpu_dev, &info->opp_nb);
+	if (info->soc_data->ccifreq_supported)
+		put_device(info->cci_dev);
 }
 
 static int mtk_cpufreq_init(struct cpufreq_policy *policy)
Signature · 1 line
2.49.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Il 09/09/25 09:38, Johan Hovold ha scritto:

Quoted 7 lines

Make sure to drop the reference to the cci device taken by of_find_device_by_node() on probe failure (e.g. probe deferral).

Fixes 0daa47325bae ("cpufreq: mediatek: Link CCI device to CPU")
Cc Jia-Wei Chang <[email protected]>
Cc Rex-BC Chen <[email protected]>
Reviewed-by on v1 1/1
#2 lore raw
In reply to Johan Hovold
Quoted 32 lines · Johan Hovold

Make sure to drop the reference to the cci device taken by of_find_device_by_node() on probe failure (e.g. probe deferral).

Fixes 0daa47325bae ("cpufreq: mediatek: Link CCI device to CPU")
Cc Jia-Wei Chang <[email protected]>
Cc Rex-BC Chen <[email protected]>
---
 drivers/cpufreq/mediatek-cpufreq.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/cpufreq/mediatek-cpufreq.c +5 -3
index f3f02c4b6888..21537a05785d 100644
@@ -404,9 +404,11 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
        }
 
        info->cpu_clk = clk_get(cpu_dev, "cpu");
-       if (IS_ERR(info->cpu_clk))
-               return dev_err_probe(cpu_dev, PTR_ERR(info->cpu_clk),
-                                    "cpu%d: failed to get cpu clk\n", cpu);
+       if (IS_ERR(info->cpu_clk)) {
+               ret = PTR_ERR(info->cpu_clk);
+               dev_err_probe(cpu_dev, ret, "cpu%d: failed to get cpu clk\n", cpu);
+               goto out_put_cci_dev;
+       }
 
        info->inter_clk = clk_get(cpu_dev, "intermediate");
        if (IS_ERR(info->inter_clk)) {

drivers/cpufreq/mediatek-cpufreq.c static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) · line 559

Quoted 6 lines
drivers/cpufreq/mediatek-cpufreq.c +3 -0
@@ -552,6 +554,10 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
 out_free_mux_clock:
        clk_put(info->cpu_clk);
 
+out_put_cci_dev:
+       if (info->soc_data->ccifreq_supported)
+               put_device(info->cci_dev);

put_device() has a check for NULL, so the if isn't really needed.

Either way,

Quoted 17 lines
drivers/cpufreq/mediatek-cpufreq.c +3 -1
+
        return ret;
 }
 
@@ -569,6 +575,8 @@ static void mtk_cpu_dvfs_info_release(struct mtk_cpu_dvfs_info *info)
        clk_put(info->inter_clk);
        dev_pm_opp_of_cpumask_remove_table(&info->cpus);
        dev_pm_opp_unregister_notifier(info->cpu_dev, &info->opp_nb);
+       if (info->soc_data->ccifreq_supported)
+               put_device(info->cci_dev);
 }
 
 static int mtk_cpufreq_init(struct cpufreq_policy *policy)
--

2.49.1

#3 lore raw
Quoted 9 lines · Chen-Yu Tsai
Quoted 8 lines · Johan Hovold

Make sure to drop the reference to the cci device taken by of_find_device_by_node() on probe failure (e.g. probe deferral).

drivers/cpufreq/mediatek-cpufreq.c +0 -0
@@ -552,6 +554,10 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
 out_free_mux_clock:
        clk_put(info->cpu_clk);
 
Quoted 5 lines

drivers/cpufreq/mediatek-cpufreq.c static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) · line 559

Quoted 3 lines
drivers/cpufreq/mediatek-cpufreq.c +3 -0
+out_put_cci_dev:
+       if (info->soc_data->ccifreq_supported)
+               put_device(info->cci_dev);

put_device() has a check for NULL, so the if isn't really needed.

I know, but this follows the pattern currently used by the driver (e.g. for regulator_put()) and avoids relying on the caller having cleared the info struct.

Quoted 3 lines

Either way,

Thanks for reviewing.

Johan

maintainer Applied
#5 lore raw
In reply to Johan Hovold
Quoted 10 lines · Johan Hovold

Make sure to drop the reference to the cci device taken by of_find_device_by_node() on probe failure (e.g. probe deferral).

Fixes 0daa47325bae ("cpufreq: mediatek: Link CCI device to CPU")
Cc Jia-Wei Chang <[email protected]>
Cc Rex-BC Chen <[email protected]>
---
 drivers/cpufreq/mediatek-cpufreq.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Applied. Thanks.

Signature · 1 line
viresh