diff mbox series

[v2] cpufreq: governor: Free dbs_data directly when gov->init() fails

Message ID 20230829070346.1217699-1-liaochang1@huawei.com (mailing list archive)
State Mainlined, archived
Headers show
Series [v2] cpufreq: governor: Free dbs_data directly when gov->init() fails | expand

Commit Message

Liao, Chang Aug. 29, 2023, 7:03 a.m. UTC
Due to the kobject embedded in the dbs_data doest not has a release()
method yet, it needs to use kfree() to free dbs_data directly when
governor fails to allocate the tunner field of dbs_data.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
 drivers/cpufreq/cpufreq_governor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Viresh Kumar Aug. 29, 2023, 7:14 a.m. UTC | #1
On 29-08-23, 07:03, Liao Chang wrote:
> Due to the kobject embedded in the dbs_data doest not has a release()
> method yet, it needs to use kfree() to free dbs_data directly when
> governor fails to allocate the tunner field of dbs_data.
> 
> Signed-off-by: Liao Chang <liaochang1@huawei.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 85da677c43d6..af44ee6a6430 100644
> --- a/drivers/cpufreq/cpufreq_governor.c
> +++ b/drivers/cpufreq/cpufreq_governor.c
> @@ -439,7 +439,7 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
>  
>  	ret = gov->init(dbs_data);
>  	if (ret)
> -		goto free_policy_dbs_info;
> +		goto free_dbs_data;
>  
>  	/*
>  	 * The sampling interval should not be less than the transition latency
> @@ -474,6 +474,8 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
>  	if (!have_governor_per_policy())
>  		gov->gdbs_data = NULL;
>  	gov->exit(dbs_data);
> +
> +free_dbs_data:
>  	kfree(dbs_data);
>  
>  free_policy_dbs_info:

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Rafael J. Wysocki Aug. 29, 2023, 6:22 p.m. UTC | #2
On Tue, Aug 29, 2023 at 9:14 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 29-08-23, 07:03, Liao Chang wrote:
> > Due to the kobject embedded in the dbs_data doest not has a release()
> > method yet, it needs to use kfree() to free dbs_data directly when
> > governor fails to allocate the tunner field of dbs_data.
> >
> > Signed-off-by: Liao Chang <liaochang1@huawei.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 85da677c43d6..af44ee6a6430 100644
> > --- a/drivers/cpufreq/cpufreq_governor.c
> > +++ b/drivers/cpufreq/cpufreq_governor.c
> > @@ -439,7 +439,7 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
> >
> >       ret = gov->init(dbs_data);
> >       if (ret)
> > -             goto free_policy_dbs_info;
> > +             goto free_dbs_data;
> >
> >       /*
> >        * The sampling interval should not be less than the transition latency
> > @@ -474,6 +474,8 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
> >       if (!have_governor_per_policy())
> >               gov->gdbs_data = NULL;
> >       gov->exit(dbs_data);
> > +
> > +free_dbs_data:
> >       kfree(dbs_data);
> >
> >  free_policy_dbs_info:
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Applied as 6.6-rc material, thanks!
diff mbox series

Patch

diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index 85da677c43d6..af44ee6a6430 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -439,7 +439,7 @@  int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
 
 	ret = gov->init(dbs_data);
 	if (ret)
-		goto free_policy_dbs_info;
+		goto free_dbs_data;
 
 	/*
 	 * The sampling interval should not be less than the transition latency
@@ -474,6 +474,8 @@  int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
 	if (!have_governor_per_policy())
 		gov->gdbs_data = NULL;
 	gov->exit(dbs_data);
+
+free_dbs_data:
 	kfree(dbs_data);
 
 free_policy_dbs_info: