Skip to content

Commit 7cca9a9

Browse files
arndbrafaeljw
authored andcommitted
cpufreq: amd-pstate: avoid uninitialized variable use
The new epp support causes warnings about three separate but related bugs: 1) failing before allocation should just return an error: drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!dev) ^~~~ drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here return ret; ^~~ 2) wrong variable to store return code: drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (rc) ^~ drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here return ret; ^~~ drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is always false if (rc) ^~~~~~~ 3) calling amd_pstate_set_epp() in cleanup path after determining that it should not be called: drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (cpudata->epp_policy == cpudata->policy) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here amd_pstate_set_epp(cpudata, epp); ^~~ All three are trivial to fix, but most likely there are additional bugs in this function when the error handling was not really tested. Fixes: ffa5096 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors") Signed-off-by: Arnd Bergmann <[email protected]> Tested-by: Wyes Karny <[email protected]> Reviewed-by: Yuan Perry <[email protected]> Acked-by: Huang Rui <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent dd329e1 commit 7cca9a9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
940940
int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
941941
struct amd_cpudata *cpudata;
942942
struct device *dev;
943-
int rc;
944943
u64 value;
945944

946945
/*
@@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
950949
amd_perf_ctl_reset(policy->cpu);
951950
dev = get_cpu_device(policy->cpu);
952951
if (!dev)
953-
goto free_cpudata1;
952+
return -ENODEV;
954953

955954
cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL);
956955
if (!cpudata)
@@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
959958
cpudata->cpu = policy->cpu;
960959
cpudata->epp_policy = 0;
961960

962-
rc = amd_pstate_init_perf(cpudata);
963-
if (rc)
961+
ret = amd_pstate_init_perf(cpudata);
962+
if (ret)
964963
goto free_cpudata1;
965964

966965
min_freq = amd_get_min_freq(cpudata);
@@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu)
10761075
value |= (u64)epp << 24;
10771076
}
10781077

1078+
amd_pstate_set_epp(cpudata, epp);
10791079
skip_epp:
10801080
WRITE_ONCE(cpudata->cppc_req_cached, value);
1081-
amd_pstate_set_epp(cpudata, epp);
10821081
cpufreq_cpu_put(policy);
10831082
}
10841083

0 commit comments

Comments
 (0)