mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks
@ 2026-11-19  5:28 Haoxiang Li
  2026-11-19  5:28 ` [PATCH v2 1/2] cpufreq: mediatek-hw: Release resources when hardware enable fails Haoxiang Li
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-11-19  5:28 UTC (permalink / raw)
  To: viresh.kumar, rafael
  Cc: zhongqiu.han, hector.yuan, matthias.bgg,
	angelogioacchino.delregno, linux-pm, linux-arm-kernel,
	linux-mediatek, linux-kernel, Haoxiang Li

This series fixes two resource cleanup omissions introduced by commit
d776790a5536 ("cpufreq: mediatek-hw: Fix double devm_remap in hotplug case").

Patch 1 releases the resources when the CPUFreq hardware fails to become
enabled.

Following Zhongqiu's suggestion during review, patch 2 handles the
additional failure path where mtk_cpu_create_freq_table() fails after
the registers have been mapped and the memory region requested.
Thanks to Zhongqiu for pointing out this omission and suggesting a
separate fix.

Changes in v2:
- Keep the original hardware enable failure fix unchanged as patch 1.
- Add patch 2 to clean up on frequency table creation failure, using
  the same Fixes tag.

Haoxiang Li (2):
  cpufreq: mediatek-hw: Release resources when hardware enable fails
  cpufreq: mediatek-hw: Clean up on frequency table creation failure

 drivers/cpufreq/mediatek-cpufreq-hw.c | 31 ++++++++++++++++-----------
 1 file changed, 18 insertions(+), 13 deletions(-)


base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
-- 
2.25.1


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

* [PATCH v2 1/2] cpufreq: mediatek-hw: Release resources when hardware enable fails
  2026-11-19  5:28 [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Haoxiang Li
@ 2026-11-19  5:28 ` Haoxiang Li
  2026-11-19  5:28 ` [PATCH v2 2/2] cpufreq: mediatek-hw: Clean up on frequency table creation failure Haoxiang Li
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-11-19  5:28 UTC (permalink / raw)
  To: viresh.kumar, rafael
  Cc: zhongqiu.han, hector.yuan, matthias.bgg,
	angelogioacchino.delregno, linux-pm, linux-arm-kernel,
	linux-mediatek, linux-kernel, 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] 5+ messages in thread

* [PATCH v2 2/2] cpufreq: mediatek-hw: Clean up on frequency table creation failure
  2026-11-19  5:28 [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Haoxiang Li
  2026-11-19  5:28 ` [PATCH v2 1/2] cpufreq: mediatek-hw: Release resources when hardware enable fails Haoxiang Li
@ 2026-11-19  5:28 ` Haoxiang Li
  2026-11-19 10:23 ` [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Zhongqiu Han
  2026-11-19 11:02 ` Viresh Kumar
  3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-11-19  5:28 UTC (permalink / raw)
  To: viresh.kumar, rafael
  Cc: zhongqiu.han, hector.yuan, matthias.bgg,
	angelogioacchino.delregno, linux-pm, linux-arm-kernel,
	linux-mediatek, linux-kernel, Haoxiang Li

If mtk_cpu_create_freq_table() fails, mtk_cpu_resources_init() returns
without unmapping the registers or releasing the memory region it has
already requested.

Unmap the registers and fall through to the existing memory-region
cleanup before returning the original error.

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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediatek-cpufreq-hw.c
index 65f15fe935db..3ab139d1a552 100644
--- a/drivers/cpufreq/mediatek-cpufreq-hw.c
+++ b/drivers/cpufreq/mediatek-cpufreq-hw.c
@@ -277,13 +277,17 @@ static int mtk_cpu_resources_init(struct platform_device *pdev,
 	ret = mtk_cpu_create_freq_table(pdev, data);
 	if (ret) {
 		dev_info(dev, "Domain-%d failed to create freq table\n", index);
-		return ret;
+		goto unmap;
 	}
 
 	policy->freq_table = data->table;
 	policy->driver_data = data;
 
 	return 0;
+
+unmap:
+	iounmap(base);
+
 release_region:
 	release_mem_region(res->start, resource_size(res));
 	return ret;
-- 
2.25.1


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

* Re: [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks
  2026-11-19  5:28 [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Haoxiang Li
  2026-11-19  5:28 ` [PATCH v2 1/2] cpufreq: mediatek-hw: Release resources when hardware enable fails Haoxiang Li
  2026-11-19  5:28 ` [PATCH v2 2/2] cpufreq: mediatek-hw: Clean up on frequency table creation failure Haoxiang Li
@ 2026-11-19 10:23 ` Zhongqiu Han
  2026-11-19 11:02 ` Viresh Kumar
  3 siblings, 0 replies; 5+ messages in thread
From: Zhongqiu Han @ 2026-11-19 10:23 UTC (permalink / raw)
  To: Haoxiang Li, viresh.kumar, rafael
  Cc: hector.yuan, matthias.bgg, angelogioacchino.delregno, linux-pm,
	linux-arm-kernel, linux-mediatek, linux-kernel, Zhongqiu Han

On 11/19/2026 1:28 PM, Haoxiang Li wrote:
> This series fixes two resource cleanup omissions introduced by commit
> d776790a5536 ("cpufreq: mediatek-hw: Fix double devm_remap in hotplug case").
> 
> Patch 1 releases the resources when the CPUFreq hardware fails to become
> enabled.
> 
> Following Zhongqiu's suggestion during review, patch 2 handles the
> additional failure path where mtk_cpu_create_freq_table() fails after
> the registers have been mapped and the memory region requested.
> Thanks to Zhongqiu for pointing out this omission and suggesting a
> separate fix.
> 
> Changes in v2:
> - Keep the original hardware enable failure fix unchanged as patch 1.
> - Add patch 2 to clean up on frequency table creation failure, using
>    the same Fixes tag.

Thanks for the update.

Side note on 1/2: if a domain's HW never comes up, subsequent CPUs of
that domain (and every CPU of it on later hotplug/resume) no longer
fail fast with -EBUSY at request_mem_region() in
mtk_cpu_resources_init(); each of them now waits for the full 300 ms
timeout. That said, HW failing to come up is already a broken platform
state, so the extra delay may not need special handling, unless
someone else sees a reason to. The code itself looks good to me.

For the series:

Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>


> 
> Haoxiang Li (2):
>    cpufreq: mediatek-hw: Release resources when hardware enable fails
>    cpufreq: mediatek-hw: Clean up on frequency table creation failure
> 
>   drivers/cpufreq/mediatek-cpufreq-hw.c | 31 ++++++++++++++++-----------
>   1 file changed, 18 insertions(+), 13 deletions(-)
> 
> 
> base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4


-- 
Thx and BRs,
Zhongqiu Han

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

* Re: [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks
  2026-11-19  5:28 [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Haoxiang Li
                   ` (2 preceding siblings ...)
  2026-11-19 10:23 ` [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Zhongqiu Han
@ 2026-11-19 11:02 ` Viresh Kumar
  3 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2026-11-19 11:02 UTC (permalink / raw)
  To: Haoxiang Li
  Cc: rafael, zhongqiu.han, hector.yuan, matthias.bgg,
	angelogioacchino.delregno, linux-pm, linux-arm-kernel,
	linux-mediatek, linux-kernel

On 19-11-26, 13:28, Haoxiang Li wrote:
> This series fixes two resource cleanup omissions introduced by commit
> d776790a5536 ("cpufreq: mediatek-hw: Fix double devm_remap in hotplug case").
> 
> Patch 1 releases the resources when the CPUFreq hardware fails to become
> enabled.
> 
> Following Zhongqiu's suggestion during review, patch 2 handles the
> additional failure path where mtk_cpu_create_freq_table() fails after
> the registers have been mapped and the memory region requested.
> Thanks to Zhongqiu for pointing out this omission and suggesting a
> separate fix.
> 
> Changes in v2:
> - Keep the original hardware enable failure fix unchanged as patch 1.
> - Add patch 2 to clean up on frequency table creation failure, using
>   the same Fixes tag.
> 
> Haoxiang Li (2):
>   cpufreq: mediatek-hw: Release resources when hardware enable fails
>   cpufreq: mediatek-hw: Clean up on frequency table creation failure

Applied. Thanks.

-- 
viresh

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

end of thread, other threads:[~2026-11-19 11:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  5:28 [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Haoxiang Li
2026-11-19  5:28 ` [PATCH v2 1/2] cpufreq: mediatek-hw: Release resources when hardware enable fails Haoxiang Li
2026-11-19  5:28 ` [PATCH v2 2/2] cpufreq: mediatek-hw: Clean up on frequency table creation failure Haoxiang Li
2026-11-19 10:23 ` [PATCH v2 0/2] cpufreq: mediatek-hw: Fix initialization resource leaks Zhongqiu Han
2026-11-19 11:02 ` Viresh Kumar

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®