[rui:amd-pstate-dev-v1 5/19] drivers/cpufreq/amd-pstate.c:243 amd_pstate_adjust_perf() error: uninitialized symbol 'amd_des_perf'.

From: Dan Carpenter
Date: Tue Sep 14 2021 - 06:33:13 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/rui/linux.git amd-pstate-dev-v1
head: abfcbc164c1aa0c63d5e256854bad977a9645586
commit: 54beca4738acc38c08710cfcb1c3312755000cf6 [5/19] cpufreq: amd: add fast switch function for amd-pstate module
config: i386-randconfig-m021-20210912 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
drivers/cpufreq/amd-pstate.c:243 amd_pstate_adjust_perf() error: uninitialized symbol 'amd_des_perf'.
drivers/cpufreq/amd-pstate.c:270 amd_pstate_fast_switch() warn: should 'amd_des_perf << 10' be a 64 bit type?

Old smatch warnings:
drivers/cpufreq/amd-pstate.c:301 amd_get_max_freq() warn: should 'max_perf << 10' be a 64 bit type?
drivers/cpufreq/amd-pstate.c:342 amd_get_lowest_nonlinear_freq() warn: should 'lowest_nonlinear_perf << 10' be a 64 bit type?

vim +/amd_des_perf +243 drivers/cpufreq/amd-pstate.c

54beca4738acc3 Huang Rui 2021-08-13 215 static void amd_pstate_adjust_perf(unsigned int cpu,
54beca4738acc3 Huang Rui 2021-08-13 216 unsigned long min_perf,
54beca4738acc3 Huang Rui 2021-08-13 217 unsigned long target_perf,
54beca4738acc3 Huang Rui 2021-08-13 218 unsigned long capacity)
54beca4738acc3 Huang Rui 2021-08-13 219 {
54beca4738acc3 Huang Rui 2021-08-13 220 unsigned long amd_max_perf, amd_min_perf, amd_des_perf,
54beca4738acc3 Huang Rui 2021-08-13 221 amd_cap_perf, lowest_nonlinear_perf;
54beca4738acc3 Huang Rui 2021-08-13 222 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
54beca4738acc3 Huang Rui 2021-08-13 223 struct amd_cpudata *cpudata = policy->driver_data;
54beca4738acc3 Huang Rui 2021-08-13 224
54beca4738acc3 Huang Rui 2021-08-13 225 amd_cap_perf = READ_ONCE(cpudata->highest_perf);
54beca4738acc3 Huang Rui 2021-08-13 226 lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
54beca4738acc3 Huang Rui 2021-08-13 227
54beca4738acc3 Huang Rui 2021-08-13 228 if (target_perf < capacity)
54beca4738acc3 Huang Rui 2021-08-13 229 amd_des_perf = DIV_ROUND_UP(amd_cap_perf * target_perf,
54beca4738acc3 Huang Rui 2021-08-13 230 capacity);

Not initialized on else path.

54beca4738acc3 Huang Rui 2021-08-13 231
54beca4738acc3 Huang Rui 2021-08-13 232 amd_min_perf = READ_ONCE(cpudata->highest_perf);
54beca4738acc3 Huang Rui 2021-08-13 233 if (min_perf < capacity)
54beca4738acc3 Huang Rui 2021-08-13 234 amd_min_perf = DIV_ROUND_UP(amd_cap_perf * min_perf, capacity);
54beca4738acc3 Huang Rui 2021-08-13 235
54beca4738acc3 Huang Rui 2021-08-13 236 if (amd_min_perf < lowest_nonlinear_perf)
54beca4738acc3 Huang Rui 2021-08-13 237 amd_min_perf = lowest_nonlinear_perf;
54beca4738acc3 Huang Rui 2021-08-13 238
54beca4738acc3 Huang Rui 2021-08-13 239 amd_max_perf = amd_cap_perf;
54beca4738acc3 Huang Rui 2021-08-13 240 if (amd_max_perf < amd_min_perf)
54beca4738acc3 Huang Rui 2021-08-13 241 amd_max_perf = amd_min_perf;
54beca4738acc3 Huang Rui 2021-08-13 242
54beca4738acc3 Huang Rui 2021-08-13 @243 amd_des_perf = clamp_t(unsigned long, amd_des_perf,
^^^^^^^^^^^^
Uninitialized.

54beca4738acc3 Huang Rui 2021-08-13 244 amd_min_perf, amd_max_perf);
54beca4738acc3 Huang Rui 2021-08-13 245
54beca4738acc3 Huang Rui 2021-08-13 246 amd_pstate_update(cpudata, amd_min_perf, amd_des_perf,
54beca4738acc3 Huang Rui 2021-08-13 247 amd_max_perf, true);
54beca4738acc3 Huang Rui 2021-08-13 248 }
54beca4738acc3 Huang Rui 2021-08-13 249
54beca4738acc3 Huang Rui 2021-08-13 250 static unsigned int amd_pstate_fast_switch(struct cpufreq_policy *policy,
54beca4738acc3 Huang Rui 2021-08-13 251 unsigned int target_freq)
54beca4738acc3 Huang Rui 2021-08-13 252 {
54beca4738acc3 Huang Rui 2021-08-13 253 u64 ratio;
54beca4738acc3 Huang Rui 2021-08-13 254 struct amd_cpudata *cpudata = policy->driver_data;
54beca4738acc3 Huang Rui 2021-08-13 255 unsigned long amd_max_perf, amd_min_perf, amd_des_perf, nominal_perf;
54beca4738acc3 Huang Rui 2021-08-13 256
54beca4738acc3 Huang Rui 2021-08-13 257 if (!cpudata->max_freq)
54beca4738acc3 Huang Rui 2021-08-13 258 return -ENODEV;
54beca4738acc3 Huang Rui 2021-08-13 259
54beca4738acc3 Huang Rui 2021-08-13 260 amd_max_perf = READ_ONCE(cpudata->highest_perf);
54beca4738acc3 Huang Rui 2021-08-13 261 amd_min_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
54beca4738acc3 Huang Rui 2021-08-13 262
54beca4738acc3 Huang Rui 2021-08-13 263 amd_des_perf = DIV_ROUND_UP(target_freq * amd_max_perf,
54beca4738acc3 Huang Rui 2021-08-13 264 cpudata->max_freq);
54beca4738acc3 Huang Rui 2021-08-13 265
54beca4738acc3 Huang Rui 2021-08-13 266 amd_pstate_update(cpudata, amd_min_perf, amd_des_perf,
54beca4738acc3 Huang Rui 2021-08-13 267 amd_max_perf, true);
54beca4738acc3 Huang Rui 2021-08-13 268
54beca4738acc3 Huang Rui 2021-08-13 269 nominal_perf = READ_ONCE(cpudata->nominal_perf);
54beca4738acc3 Huang Rui 2021-08-13 @270 ratio = div_u64(amd_des_perf << SCHED_CAPACITY_SHIFT, nominal_perf);

Should amd_des_perf be a u64? Does that matter on 32 bit systems?

54beca4738acc3 Huang Rui 2021-08-13 271
54beca4738acc3 Huang Rui 2021-08-13 272 return cpudata->nominal_freq * ratio >> SCHED_CAPACITY_SHIFT;
54beca4738acc3 Huang Rui 2021-08-13 273 }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx