[PATCH 09/12] cpufreq/amd-pstate: Fix cpufreq_policy ref counting

Dhananjay Ugwekar posted 12 patches 10 months, 1 week ago
[PATCH 09/12] cpufreq/amd-pstate: Fix cpufreq_policy ref counting
Posted by Dhananjay Ugwekar 10 months, 1 week ago
amd_pstate_update_limits() takes a cpufreq_policy reference but doesn't
decrement the refcount in one of the exit paths, fix that.

Fixes: 45722e777fd9 ("cpufreq: amd-pstate: Optimize amd_pstate_update_limits()")
Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>
---
 drivers/cpufreq/amd-pstate.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 107ad953ce43..9c939be59042 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -821,20 +821,21 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
 
 static void amd_pstate_update_limits(unsigned int cpu)
 {
-	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
+	struct cpufreq_policy *policy = NULL;
 	struct amd_cpudata *cpudata;
 	u32 prev_high = 0, cur_high = 0;
 	int ret;
 	bool highest_perf_changed = false;
 
+	if (!amd_pstate_prefcore)
+		return;
+
+	policy = cpufreq_cpu_get(cpu);
 	if (!policy)
 		return;
 
 	cpudata = policy->driver_data;
 
-	if (!amd_pstate_prefcore)
-		return;
-
 	guard(mutex)(&amd_pstate_driver_lock);
 
 	ret = amd_get_highest_perf(cpu, &cur_high);
-- 
2.34.1
Re: [PATCH 09/12] cpufreq/amd-pstate: Fix cpufreq_policy ref counting
Posted by Gautham R. Shenoy 10 months, 1 week ago
On Wed, Feb 05, 2025 at 11:25:20AM +0000, Dhananjay Ugwekar wrote:
> amd_pstate_update_limits() takes a cpufreq_policy reference but doesn't
> decrement the refcount in one of the exit paths, fix that.
> 
> Fixes: 45722e777fd9 ("cpufreq: amd-pstate: Optimize amd_pstate_update_limits()")
> Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>

Thanks for fixing this.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>

-- 
Thanks and Regards
gautham.

> ---
>  drivers/cpufreq/amd-pstate.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 107ad953ce43..9c939be59042 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -821,20 +821,21 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
>  
>  static void amd_pstate_update_limits(unsigned int cpu)
>  {
> -	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
> +	struct cpufreq_policy *policy = NULL;
>  	struct amd_cpudata *cpudata;
>  	u32 prev_high = 0, cur_high = 0;
>  	int ret;
>  	bool highest_perf_changed = false;
>  
> +	if (!amd_pstate_prefcore)
> +		return;
> +
> +	policy = cpufreq_cpu_get(cpu);
>  	if (!policy)
>  		return;
>  
>  	cpudata = policy->driver_data;
>  
> -	if (!amd_pstate_prefcore)
> -		return;
> -
>  	guard(mutex)(&amd_pstate_driver_lock);
>  
>  	ret = amd_get_highest_perf(cpu, &cur_high);
> -- 
> 2.34.1
>
Re: [PATCH 09/12] cpufreq/amd-pstate: Fix cpufreq_policy ref counting
Posted by Mario Limonciello 10 months, 1 week ago
On 2/5/2025 05:25, Dhananjay Ugwekar wrote:
> amd_pstate_update_limits() takes a cpufreq_policy reference but doesn't
> decrement the refcount in one of the exit paths, fix that.
> 
> Fixes: 45722e777fd9 ("cpufreq: amd-pstate: Optimize amd_pstate_update_limits()")
> Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>

Thanks.

Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>

I'll queue this fix for 6.14-rc.
> ---
>   drivers/cpufreq/amd-pstate.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 107ad953ce43..9c939be59042 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -821,20 +821,21 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
>   
>   static void amd_pstate_update_limits(unsigned int cpu)
>   {
> -	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
> +	struct cpufreq_policy *policy = NULL;
>   	struct amd_cpudata *cpudata;
>   	u32 prev_high = 0, cur_high = 0;
>   	int ret;
>   	bool highest_perf_changed = false;
>   
> +	if (!amd_pstate_prefcore)
> +		return;
> +
> +	policy = cpufreq_cpu_get(cpu);
>   	if (!policy)
>   		return;
>   
>   	cpudata = policy->driver_data;
>   
> -	if (!amd_pstate_prefcore)
> -		return;
> -
>   	guard(mutex)(&amd_pstate_driver_lock);
>   
>   	ret = amd_get_highest_perf(cpu, &cur_high);