From: Haoxiang Li <haoxiang_li2024@163.com>
To: viresh.kumar@linaro.org, rafael@kernel.org
Cc: zhongqiu.han@oss.qualcomm.com, hector.yuan@mediatek.com,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
Haoxiang Li <haoxiang_li2024@163.com>
Subject: [PATCH v2 1/2] cpufreq: mediatek-hw: Release resources when hardware enable fails
Date: Thu, 19 Nov 2026 13:28:10 +0800 [thread overview]
Message-ID: <20261119052811.2877720-2-haoxiang_li2024@163.com> (raw)
In-Reply-To: <20261119052811.2877720-1-haoxiang_li2024@163.com>
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
next prev parent reply other threads:[~2026-11-19 5:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119052811.2877720-2-haoxiang_li2024@163.com \
--to=haoxiang_li2024@163.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=hector.yuan@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=zhongqiu.han@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®