diff mbox series

cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe()

Message ID 1603113151-5219-1-git-send-email-bodefang@126.com (mailing list archive)
State New, archived
Delegated to: viresh kumar
Headers show
Series cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe() | expand

Commit Message

Defang Bo Oct. 19, 2020, 1:12 p.m. UTC
Similar to commit<05829d9431df>("cpufreq: ti-cpufreq: kfree opp_data when failure"), opp_data needs to be freed when failure, including fail_put_node.

Signed-off-by: Defang Bo <bodefang@126.com>
---
 drivers/cpufreq/ti-cpufreq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Viresh Kumar Oct. 20, 2020, 7:42 a.m. UTC | #1
On 19-10-20, 21:12, Defang Bo wrote:
> Similar to commit<05829d9431df>("cpufreq: ti-cpufreq: kfree opp_data when failure"), opp_data needs to be freed when failure, including fail_put_node.

This is allocated using devm_kzalloc() and so we don't need to free it
explicitly.

> Signed-off-by: Defang Bo <bodefang@126.com>
> ---
>  drivers/cpufreq/ti-cpufreq.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
> index ab0de27..f23be8f 100644
> --- a/drivers/cpufreq/ti-cpufreq.c
> +++ b/drivers/cpufreq/ti-cpufreq.c
> @@ -342,7 +342,8 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
>  	opp_data->cpu_dev = get_cpu_device(0);
>  	if (!opp_data->cpu_dev) {
>  		pr_err("%s: Failed to get device for CPU0\n", __func__);
> -		return -ENODEV;
> +		ret = ENODEV;
> +		goto free_opp_data;
>  	}
>  
>  	opp_data->opp_node = dev_pm_opp_of_get_opp_desc_node(opp_data->cpu_dev);
> @@ -404,7 +405,8 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
>  
>  fail_put_node:
>  	of_node_put(opp_data->opp_node);
> -
> +free_opp_data:
> +	kfree(opp_data)

Did you even try to compile this code ?

>  	return ret;
>  }
>  
> -- 
> 1.9.1
diff mbox series

Patch

diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
index ab0de27..f23be8f 100644
--- a/drivers/cpufreq/ti-cpufreq.c
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -342,7 +342,8 @@  static int ti_cpufreq_probe(struct platform_device *pdev)
 	opp_data->cpu_dev = get_cpu_device(0);
 	if (!opp_data->cpu_dev) {
 		pr_err("%s: Failed to get device for CPU0\n", __func__);
-		return -ENODEV;
+		ret = ENODEV;
+		goto free_opp_data;
 	}
 
 	opp_data->opp_node = dev_pm_opp_of_get_opp_desc_node(opp_data->cpu_dev);
@@ -404,7 +405,8 @@  static int ti_cpufreq_probe(struct platform_device *pdev)
 
 fail_put_node:
 	of_node_put(opp_data->opp_node);
-
+free_opp_data:
+	kfree(opp_data)
 	return ret;
 }