linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq/cpufreq_governor: Fix memory leak in cpufreq_dbs_governor_init
@ 2019-10-09 23:26 Navid Emamdoost
  2019-10-10  6:49 ` Viresh Kumar
  0 siblings, 1 reply; 2+ messages in thread
From: Navid Emamdoost @ 2019-10-09 23:26 UTC (permalink / raw)
  Cc: emamd001, kjlu, smccaman, Navid Emamdoost, Rafael J. Wysocki,
	Viresh Kumar, linux-pm, linux-kernel

In the implementation of cpufreq_dbs_governor_init(), dbs_data is
allocated and later is assigned to governor_data. But before that
assignment, if gov->init() fails this allocation is not released.
dbs_data should be released in case if gov->init() failure.

Fixes: 714a2d9c8792 ("cpufreq: governor: split cpufreq_governor_dbs()")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/cpufreq/cpufreq_governor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index 4bb054d0cb43..deb099d36266 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -428,8 +428,10 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
 	gov_attr_set_init(&dbs_data->attr_set, &policy_dbs->list);
 
 	ret = gov->init(dbs_data);
-	if (ret)
+	if (ret) {
+		kfree(dbs_data);
 		goto free_policy_dbs_info;
+	}
 
 	/*
 	 * The sampling interval should not be less than the transition latency
-- 
2.17.1


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

* Re: [PATCH] cpufreq/cpufreq_governor: Fix memory leak in cpufreq_dbs_governor_init
  2019-10-09 23:26 [PATCH] cpufreq/cpufreq_governor: Fix memory leak in cpufreq_dbs_governor_init Navid Emamdoost
@ 2019-10-10  6:49 ` Viresh Kumar
  0 siblings, 0 replies; 2+ messages in thread
From: Viresh Kumar @ 2019-10-10  6:49 UTC (permalink / raw)
  To: Navid Emamdoost
  Cc: emamd001, kjlu, smccaman, Rafael J. Wysocki, linux-pm, linux-kernel

On 09-10-19, 18:26, Navid Emamdoost wrote:
> In the implementation of cpufreq_dbs_governor_init(), dbs_data is
> allocated and later is assigned to governor_data. But before that
> assignment, if gov->init() fails this allocation is not released.
> dbs_data should be released in case if gov->init() failure.
> 
> Fixes: 714a2d9c8792 ("cpufreq: governor: split cpufreq_governor_dbs()")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  drivers/cpufreq/cpufreq_governor.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
> index 4bb054d0cb43..deb099d36266 100644
> --- a/drivers/cpufreq/cpufreq_governor.c
> +++ b/drivers/cpufreq/cpufreq_governor.c
> @@ -428,8 +428,10 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
>  	gov_attr_set_init(&dbs_data->attr_set, &policy_dbs->list);
>  
>  	ret = gov->init(dbs_data);
> -	if (ret)
> +	if (ret) {
> +		kfree(dbs_data);
>  		goto free_policy_dbs_info;

Maybe add another label right before kfree() at the bottom and jump there
instead. We wanted to share code in the error path.

> +	}
>  
>  	/*
>  	 * The sampling interval should not be less than the transition latency
> -- 
> 2.17.1

-- 
viresh

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

end of thread, other threads:[~2019-10-10  6:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 23:26 [PATCH] cpufreq/cpufreq_governor: Fix memory leak in cpufreq_dbs_governor_init Navid Emamdoost
2019-10-10  6:49 ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).