[PATCH 5/7] cpufreq: Move the check of cpufreq_driver->get into cpufreq_verify_current_freq()

Lifeng Zheng posted 7 patches 3 months, 2 weeks ago
[PATCH 5/7] cpufreq: Move the check of cpufreq_driver->get into cpufreq_verify_current_freq()
Posted by Lifeng Zheng 3 months, 2 weeks ago
Move the check of cpufreq_driver->get into cpufreq_verify_current_freq() in
case of calling it without check.

Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
---
 drivers/cpufreq/cpufreq.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index c4891bf5dc84..9b2578b905a5 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1800,6 +1800,9 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b
 {
 	unsigned int new_freq;
 
+	if (!cpufreq_driver->get)
+		return 0;
+
 	new_freq = cpufreq_driver->get(policy->cpu);
 	if (!new_freq)
 		return 0;
@@ -1922,10 +1925,7 @@ unsigned int cpufreq_get(unsigned int cpu)
 
 	guard(cpufreq_policy_read)(policy);
 
-	if (cpufreq_driver->get)
-		return __cpufreq_get(policy);
-
-	return 0;
+	return __cpufreq_get(policy);
 }
 EXPORT_SYMBOL(cpufreq_get);
 
@@ -2479,8 +2479,7 @@ int cpufreq_start_governor(struct cpufreq_policy *policy)
 
 	pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
 
-	if (cpufreq_driver->get)
-		cpufreq_verify_current_freq(policy, false);
+	cpufreq_verify_current_freq(policy, false);
 
 	if (policy->governor->start) {
 		ret = policy->governor->start(policy);
-- 
2.33.0
Re: [PATCH 5/7] cpufreq: Move the check of cpufreq_driver->get into cpufreq_verify_current_freq()
Posted by Rafael J. Wysocki 3 months, 2 weeks ago
On Mon, Jun 23, 2025 at 3:34 PM Lifeng Zheng <zhenglifeng1@huawei.com> wrote:
>
> Move the check of cpufreq_driver->get into cpufreq_verify_current_freq() in
> case of calling it without check.
>
> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
> ---
>  drivers/cpufreq/cpufreq.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index c4891bf5dc84..9b2578b905a5 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1800,6 +1800,9 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b
>  {
>         unsigned int new_freq;
>
> +       if (!cpufreq_driver->get)
> +               return 0;
> +

This will duplicate the check in cpufreq_policy_refresh(), won't it?

>         new_freq = cpufreq_driver->get(policy->cpu);
>         if (!new_freq)
>                 return 0;
> @@ -1922,10 +1925,7 @@ unsigned int cpufreq_get(unsigned int cpu)
>
>         guard(cpufreq_policy_read)(policy);
>
> -       if (cpufreq_driver->get)
> -               return __cpufreq_get(policy);
> -
> -       return 0;
> +       return __cpufreq_get(policy);
>  }
>  EXPORT_SYMBOL(cpufreq_get);
>
> @@ -2479,8 +2479,7 @@ int cpufreq_start_governor(struct cpufreq_policy *policy)
>
>         pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
>
> -       if (cpufreq_driver->get)
> -               cpufreq_verify_current_freq(policy, false);
> +       cpufreq_verify_current_freq(policy, false);
>
>         if (policy->governor->start) {
>                 ret = policy->governor->start(policy);
> --
> 2.33.0
>
Re: [PATCH 5/7] cpufreq: Move the check of cpufreq_driver->get into cpufreq_verify_current_freq()
Posted by zhenglifeng (A) 3 months ago
On 2025/6/23 23:35, Rafael J. Wysocki wrote:

> On Mon, Jun 23, 2025 at 3:34 PM Lifeng Zheng <zhenglifeng1@huawei.com> wrote:
>>
>> Move the check of cpufreq_driver->get into cpufreq_verify_current_freq() in
>> case of calling it without check.
>>
>> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
>> ---
>>  drivers/cpufreq/cpufreq.c | 11 +++++------
>>  1 file changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index c4891bf5dc84..9b2578b905a5 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -1800,6 +1800,9 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b
>>  {
>>         unsigned int new_freq;
>>
>> +       if (!cpufreq_driver->get)
>> +               return 0;
>> +
> 
> This will duplicate the check in cpufreq_policy_refresh(), won't it?

Yes, the check will duplicate but I think it's OK. If remove the check in
cpufreq_policy_refresh(), the logic will be changed.

> 
>>         new_freq = cpufreq_driver->get(policy->cpu);
>>         if (!new_freq)
>>                 return 0;
>> @@ -1922,10 +1925,7 @@ unsigned int cpufreq_get(unsigned int cpu)
>>
>>         guard(cpufreq_policy_read)(policy);
>>
>> -       if (cpufreq_driver->get)
>> -               return __cpufreq_get(policy);
>> -
>> -       return 0;
>> +       return __cpufreq_get(policy);
>>  }
>>  EXPORT_SYMBOL(cpufreq_get);
>>
>> @@ -2479,8 +2479,7 @@ int cpufreq_start_governor(struct cpufreq_policy *policy)
>>
>>         pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
>>
>> -       if (cpufreq_driver->get)
>> -               cpufreq_verify_current_freq(policy, false);
>> +       cpufreq_verify_current_freq(policy, false);
>>
>>         if (policy->governor->start) {
>>                 ret = policy->governor->start(policy);
>> --
>> 2.33.0
>>