mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cpufreq: mediatek-hw: Release resources when hardware enable fails
@ 2026-11-18  3:42 Haoxiang Li
  2026-11-18  4:15 ` Zhongqiu Han
  0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2026-11-18  3:42 UTC (permalink / raw)
  To: rafael, viresh.kumar, matthias.bgg, angelogioacchino.delregno,
	hector.yuan
  Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek, Haoxiang Li

If the CPUFreq hardware fails to become enabled, mtk_cpufreq_hw_cpu_init()
directly returns -ENODEV without releasing allocated resources.

Reuse mtk_cpufreq_hw_cpu_exit() on this error path to clear the hardware
enable request, unmap the registers and release the memory region.

Fixes: d776790a5536 ("cpufreq: mediatek-hw: Fix double devm_remap in hotplug case")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/cpufreq/mediatek-cpufreq-hw.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediatek-cpufreq-hw.c
index 2c57371ad502..65f15fe935db 100644
--- a/drivers/cpufreq/mediatek-cpufreq-hw.c
+++ b/drivers/cpufreq/mediatek-cpufreq-hw.c
@@ -289,6 +289,18 @@ static int mtk_cpu_resources_init(struct platform_device *pdev,
 	return ret;
 }
 
+static void mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
+{
+	struct mtk_cpufreq_domain *data = policy->driver_data;
+	struct resource *res = data->res;
+	void __iomem *base = data->base;
+
+	/* HW should be in paused state now */
+	writel_relaxed(0x0, data->reg_bases[REG_FREQ_ENABLE]);
+	iounmap(base);
+	release_mem_region(res->start, resource_size(res));
+}
+
 static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
 {
 	struct platform_device *pdev = cpufreq_get_driver_data();
@@ -321,6 +333,7 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
 		if (!(sig & CPUFREQ_HW_STATUS)) {
 			pr_info("cpufreq hardware of CPU%d is not enabled\n",
 				policy->cpu);
+			mtk_cpufreq_hw_cpu_exit(policy);
 			return -ENODEV;
 		}
 
@@ -330,18 +343,6 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
 	return 0;
 }
 
-static void mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
-{
-	struct mtk_cpufreq_domain *data = policy->driver_data;
-	struct resource *res = data->res;
-	void __iomem *base = data->base;
-
-	/* HW should be in paused state now */
-	writel_relaxed(0x0, data->reg_bases[REG_FREQ_ENABLE]);
-	iounmap(base);
-	release_mem_region(res->start, resource_size(res));
-}
-
 static void mtk_cpufreq_register_em(struct cpufreq_policy *policy)
 {
 	struct em_data_callback em_cb = EM_DATA_CB(mtk_cpufreq_get_cpu_power);
-- 
2.25.1


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

* Re: [PATCH] cpufreq: mediatek-hw: Release resources when hardware enable fails
  2026-11-18  3:42 [PATCH] cpufreq: mediatek-hw: Release resources when hardware enable fails Haoxiang Li
@ 2026-11-18  4:15 ` Zhongqiu Han
  0 siblings, 0 replies; 2+ messages in thread
From: Zhongqiu Han @ 2026-11-18  4:15 UTC (permalink / raw)
  To: Haoxiang Li, rafael, viresh.kumar, matthias.bgg,
	angelogioacchino.delregno, hector.yuan
  Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek, Zhongqiu Han

On 11/18/2026 11:42 AM, Haoxiang Li wrote:
> If the CPUFreq hardware fails to become enabled, mtk_cpufreq_hw_cpu_init()
> directly returns -ENODEV without releasing allocated resources.
> 
> Reuse mtk_cpufreq_hw_cpu_exit() on this error path to clear the hardware
> enable request, unmap the registers and release the memory region.
> 
> Fixes: d776790a5536 ("cpufreq: mediatek-hw: Fix double devm_remap in hotplug case")


The same commit also introduced a leak in mtk_cpu_resources_init():
when mtk_cpu_create_freq_table() fails, it returns without iounmap()
and release_mem_region(). Could you fix that path too, as a separate
patch in a v2 series with the same Fixes tag?


> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
>   drivers/cpufreq/mediatek-cpufreq-hw.c | 25 +++++++++++++------------
>   1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediatek-cpufreq-hw.c
> index 2c57371ad502..65f15fe935db 100644
> --- a/drivers/cpufreq/mediatek-cpufreq-hw.c
> +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c
> @@ -289,6 +289,18 @@ static int mtk_cpu_resources_init(struct platform_device *pdev,
>   	return ret;
>   }
>   
> +static void mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
> +{
> +	struct mtk_cpufreq_domain *data = policy->driver_data;
> +	struct resource *res = data->res;
> +	void __iomem *base = data->base;
> +
> +	/* HW should be in paused state now */
> +	writel_relaxed(0x0, data->reg_bases[REG_FREQ_ENABLE]);
> +	iounmap(base);
> +	release_mem_region(res->start, resource_size(res));
> +}
> +
>   static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
>   {
>   	struct platform_device *pdev = cpufreq_get_driver_data();
> @@ -321,6 +333,7 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
>   		if (!(sig & CPUFREQ_HW_STATUS)) {
>   			pr_info("cpufreq hardware of CPU%d is not enabled\n",
>   				policy->cpu);
> +			mtk_cpufreq_hw_cpu_exit(policy);
>   			return -ENODEV;
>   		}
>   
> @@ -330,18 +343,6 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
>   	return 0;
>   }
>   
> -static void mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
> -{
> -	struct mtk_cpufreq_domain *data = policy->driver_data;
> -	struct resource *res = data->res;
> -	void __iomem *base = data->base;
> -
> -	/* HW should be in paused state now */
> -	writel_relaxed(0x0, data->reg_bases[REG_FREQ_ENABLE]);
> -	iounmap(base);
> -	release_mem_region(res->start, resource_size(res));
> -}
> -
>   static void mtk_cpufreq_register_em(struct cpufreq_policy *policy)
>   {
>   	struct em_data_callback em_cb = EM_DATA_CB(mtk_cpufreq_get_cpu_power);


-- 
Thx and BRs,
Zhongqiu Han

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

end of thread, other threads:[~2026-11-18  4:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  3:42 [PATCH] cpufreq: mediatek-hw: Release resources when hardware enable fails Haoxiang Li
2026-11-18  4:15 ` Zhongqiu Han

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

all inboxes | Powered by JetHome®