mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cpufreq: governor: Free dbs_data directly when gov->init() fails
@ 2023-08-26  1:24 Liao Chang
  2023-08-28  6:56 ` Viresh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Liao Chang @ 2023-08-26  1:24 UTC (permalink / raw)
  To: rafael, viresh.kumar; +Cc: linux-pm, linux-kernel

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..6e1ac864e87e 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -438,8 +438,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.34.1


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

* Re: [PATCH] cpufreq: governor: Free dbs_data directly when gov->init() fails
  2023-08-26  1:24 [PATCH] cpufreq: governor: Free dbs_data directly when gov->init() fails Liao Chang
@ 2023-08-28  6:56 ` Viresh Kumar
  2023-08-28  7:25   ` Liao, Chang
  0 siblings, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2023-08-28  6:56 UTC (permalink / raw)
  To: Liao Chang; +Cc: rafael, linux-pm, linux-kernel

On 26-08-23, 01:24, 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..6e1ac864e87e 100644
> --- a/drivers/cpufreq/cpufreq_governor.c
> +++ b/drivers/cpufreq/cpufreq_governor.c
> @@ -438,8 +438,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;
> +	}

What about this instead ?

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:

-- 
viresh

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

* Re: [PATCH] cpufreq: governor: Free dbs_data directly when gov->init() fails
  2023-08-28  6:56 ` Viresh Kumar
@ 2023-08-28  7:25   ` Liao, Chang
  2023-08-28  7:27     ` Viresh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Liao, Chang @ 2023-08-28  7:25 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: rafael, linux-pm, linux-kernel

Hi Viresh.

在 2023/8/28 14:56, Viresh Kumar 写道:
> On 26-08-23, 01:24, 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..6e1ac864e87e 100644
>> --- a/drivers/cpufreq/cpufreq_governor.c
>> +++ b/drivers/cpufreq/cpufreq_governor.c
>> @@ -438,8 +438,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;
>> +	}
> 
> What about this instead ?
> 
> 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);

Sure, less copy-and-paste code is better :)

Do you mind I copy above code in next revision?

Thanks.

> 
>  free_policy_dbs_info:
> 

-- 
BR
Liao, Chang

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

* Re: [PATCH] cpufreq: governor: Free dbs_data directly when gov->init() fails
  2023-08-28  7:25   ` Liao, Chang
@ 2023-08-28  7:27     ` Viresh Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2023-08-28  7:27 UTC (permalink / raw)
  To: Liao, Chang; +Cc: rafael, linux-pm, linux-kernel

On 28-08-23, 15:25, Liao, Chang wrote:
> Sure, less copy-and-paste code is better :)
> 
> Do you mind I copy above code in next revision?

Please do.

-- 
viresh

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

end of thread, other threads:[~2023-08-28  7:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-26  1:24 [PATCH] cpufreq: governor: Free dbs_data directly when gov->init() fails Liao Chang
2023-08-28  6:56 ` Viresh Kumar
2023-08-28  7:25   ` Liao, Chang
2023-08-28  7:27     ` 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®