From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: Haoxiang Li <haoxiang_li2024@163.com>,
rafael@kernel.org, viresh.kumar@linaro.org,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
hector.yuan@mediatek.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
Subject: Re: [PATCH] cpufreq: mediatek-hw: Release resources when hardware enable fails
Date: Wed, 18 Nov 2026 12:15:32 +0800 [thread overview]
Message-ID: <c310d7ef-28cc-4ad0-9414-8b5ead52f53c@oss.qualcomm.com> (raw)
In-Reply-To: <20261118034205.2002363-1-haoxiang_li2024@163.com>
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
prev parent reply other threads:[~2026-11-18 4:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 3:42 Haoxiang Li
2026-11-18 4:15 ` Zhongqiu Han [this message]
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=c310d7ef-28cc-4ad0-9414-8b5ead52f53c@oss.qualcomm.com \
--to=zhongqiu.han@oss.qualcomm.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=haoxiang_li2024@163.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 \
/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®