[PATCH 10/12] cpufreq/amd-pstate: Add missing NULL ptr check in amd_pstate_update

Dhananjay Ugwekar posted 12 patches 10 months, 1 week ago
[PATCH 10/12] cpufreq/amd-pstate: Add missing NULL ptr check in amd_pstate_update
Posted by Dhananjay Ugwekar 10 months, 1 week ago
Check if policy is NULL before dereferencing it in amd_pstate_update.

Fixes: e8f555daacd3 ("cpufreq/amd-pstate: fix setting policy current frequency value")
Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>
---
 drivers/cpufreq/amd-pstate.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 9c939be59042..6a604f0797d9 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -551,6 +551,9 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u8 min_perf,
 	struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu);
 	u8 nominal_perf = READ_ONCE(cpudata->nominal_perf);
 
+	if (!policy)
+		return;
+
 	des_perf = clamp_t(u8, des_perf, min_perf, max_perf);
 
 	policy->cur = perf_to_freq(cpudata, des_perf);
-- 
2.34.1
Re: [PATCH 10/12] cpufreq/amd-pstate: Add missing NULL ptr check in amd_pstate_update
Posted by Gautham R. Shenoy 10 months, 1 week ago
On Wed, Feb 05, 2025 at 11:25:21AM +0000, Dhananjay Ugwekar wrote:
> Check if policy is NULL before dereferencing it in amd_pstate_update.

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

-- 
Thanks and Regards
gautham.


> 
> Fixes: e8f555daacd3 ("cpufreq/amd-pstate: fix setting policy current frequency value")
> Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>
> ---
>  drivers/cpufreq/amd-pstate.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 9c939be59042..6a604f0797d9 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -551,6 +551,9 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u8 min_perf,
>  	struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu);
>  	u8 nominal_perf = READ_ONCE(cpudata->nominal_perf);
>  
> +	if (!policy)
> +		return;
> +
>  	des_perf = clamp_t(u8, des_perf, min_perf, max_perf);
>  
>  	policy->cur = perf_to_freq(cpudata, des_perf);
> -- 
> 2.34.1
>
Re: [PATCH 10/12] cpufreq/amd-pstate: Add missing NULL ptr check in amd_pstate_update
Posted by Mario Limonciello 10 months, 1 week ago
On 2/5/2025 05:25, Dhananjay Ugwekar wrote:
> Check if policy is NULL before dereferencing it in amd_pstate_update.
> 
> Fixes: e8f555daacd3 ("cpufreq/amd-pstate: fix setting policy current frequency value")
> 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 | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 9c939be59042..6a604f0797d9 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -551,6 +551,9 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u8 min_perf,
>   	struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu);
>   	u8 nominal_perf = READ_ONCE(cpudata->nominal_perf);
>   
> +	if (!policy)
> +		return;
> +
>   	des_perf = clamp_t(u8, des_perf, min_perf, max_perf);
>   
>   	policy->cur = perf_to_freq(cpudata, des_perf);