Skip to content

Commit 5493f97

Browse files
Anastasia Belovavireshk
authored andcommitted
cpufreq: amd-pstate: add check for cpufreq_cpu_get's return value
cpufreq_cpu_get may return NULL. To avoid NULL-dereference check it and return in case of error. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Anastasia Belova <[email protected]> Reviewed-by: Perry Yuan <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent b14ceb8 commit 5493f97

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,12 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
659659
unsigned long max_perf, min_perf, des_perf,
660660
cap_perf, lowest_nonlinear_perf;
661661
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
662-
struct amd_cpudata *cpudata = policy->driver_data;
662+
struct amd_cpudata *cpudata;
663+
664+
if (!policy)
665+
return;
666+
667+
cpudata = policy->driver_data;
663668

664669
if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq)
665670
amd_pstate_update_min_max_limit(policy);
@@ -873,11 +878,16 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
873878
static void amd_pstate_update_limits(unsigned int cpu)
874879
{
875880
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
876-
struct amd_cpudata *cpudata = policy->driver_data;
881+
struct amd_cpudata *cpudata;
877882
u32 prev_high = 0, cur_high = 0;
878883
int ret;
879884
bool highest_perf_changed = false;
880885

886+
if (!policy)
887+
return;
888+
889+
cpudata = policy->driver_data;
890+
881891
mutex_lock(&amd_pstate_driver_lock);
882892
if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore))
883893
goto free_cpufreq_put;

0 commit comments

Comments
 (0)