* [PATCH v2] cpufreq: mediatek: Fix resource leaks on mtk_cpu_create_freq_table() failure
@ 2024-09-07 16:36 Riyan Dhiman
2024-10-01 5:39 ` Viresh Kumar
0 siblings, 1 reply; 4+ messages in thread
From: Riyan Dhiman @ 2024-09-07 16:36 UTC (permalink / raw)
To: rafael, viresh.kumar; +Cc: linux-pm, linux-kernel, Riyan Dhiman
If mtk_cpu_create_freq_table() fails then there is a potential resource leak because
memory region is not released and IO memory is not unmapped.
Added error handling to ensure proper cleanup of all resources on failure, preventing potential leaks.
Fixes: d776790a5536 (cpufreq: mediatek-hw: Fix double devm_remap in hotplug case)
Signed-off-by: Riyan Dhiman <riyandhiman14@gmail.com>
---
It is more of a extension of the above commit as this error handling was missing in that commit.
v2: Fix commit message.
v1: Added error handling.
drivers/cpufreq/mediatek-cpufreq-hw.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediatek-cpufreq-hw.c
index 8925e096d5b9..3b1303f350ec 100644
--- a/drivers/cpufreq/mediatek-cpufreq-hw.c
+++ b/drivers/cpufreq/mediatek-cpufreq-hw.c
@@ -207,13 +207,15 @@ 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_region;
}
policy->freq_table = data->table;
policy->driver_data = data;
return 0;
+unmap_region:
+ iounmap(base);
release_region:
release_mem_region(res->start, resource_size(res));
return ret;
--
2.46.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] cpufreq: mediatek: Fix resource leaks on mtk_cpu_create_freq_table() failure
2024-09-07 16:36 [PATCH v2] cpufreq: mediatek: Fix resource leaks on mtk_cpu_create_freq_table() failure Riyan Dhiman
@ 2024-10-01 5:39 ` Viresh Kumar
2024-10-01 11:28 ` Riyan Dhiman
0 siblings, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2024-10-01 5:39 UTC (permalink / raw)
To: Riyan Dhiman; +Cc: rafael, linux-pm, linux-kernel
On 07-09-24, 22:06, Riyan Dhiman wrote:
> If mtk_cpu_create_freq_table() fails then there is a potential resource leak because
> memory region is not released and IO memory is not unmapped.
> Added error handling to ensure proper cleanup of all resources on failure, preventing potential leaks.
>
> Fixes: d776790a5536 (cpufreq: mediatek-hw: Fix double devm_remap in hotplug case)
>
> Signed-off-by: Riyan Dhiman <riyandhiman14@gmail.com>
> ---
> It is more of a extension of the above commit as this error handling was missing in that commit.
>
> v2: Fix commit message.
> v1: Added error handling.
>
> drivers/cpufreq/mediatek-cpufreq-hw.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediatek-cpufreq-hw.c
> index 8925e096d5b9..3b1303f350ec 100644
> --- a/drivers/cpufreq/mediatek-cpufreq-hw.c
> +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c
> @@ -207,13 +207,15 @@ 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_region;
> }
>
> policy->freq_table = data->table;
> policy->driver_data = data;
>
> return 0;
> +unmap_region:
> + iounmap(base);
Since this driver already uses devm_* APIs, what about using them
instead ?
--
viresh
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] cpufreq: mediatek: Fix resource leaks on mtk_cpu_create_freq_table() failure
2024-10-01 5:39 ` Viresh Kumar
@ 2024-10-01 11:28 ` Riyan Dhiman
2024-10-03 4:08 ` Viresh Kumar
0 siblings, 1 reply; 4+ messages in thread
From: Riyan Dhiman @ 2024-10-01 11:28 UTC (permalink / raw)
To: viresh.kumar, rafael; +Cc: linux-pm, linux-kernel
> Since this driver already uses devm_* APIs, what about using them
> instead ?
Since ioremap was called that's why I added a goto statement to handle
the cleanup.
In this file, devm_kzalloc and devm_regulator_get are called. Do I need
to call this devm_platform_ioremap_resource instead of ioremap if devm_*
api need to be used?
Regards,
Riyan Dhiman
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] cpufreq: mediatek: Fix resource leaks on mtk_cpu_create_freq_table() failure
2024-10-01 11:28 ` Riyan Dhiman
@ 2024-10-03 4:08 ` Viresh Kumar
0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2024-10-03 4:08 UTC (permalink / raw)
To: Riyan Dhiman; +Cc: rafael, linux-pm, linux-kernel
On 01-10-24, 16:58, Riyan Dhiman wrote:
> In this file, devm_kzalloc and devm_regulator_get are called. Do I need
> to call this devm_platform_ioremap_resource instead of ioremap if devm_*
> api need to be used?
Yes, that would do.
--
viresh
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-03 4:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-07 16:36 [PATCH v2] cpufreq: mediatek: Fix resource leaks on mtk_cpu_create_freq_table() failure Riyan Dhiman
2024-10-01 5:39 ` Viresh Kumar
2024-10-01 11:28 ` Riyan Dhiman
2024-10-03 4:08 ` 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®