Skip to content

Commit edf8ba3

Browse files
bwhacksgregkh
authored andcommitted
tools/power x86_energy_perf_policy: Fix "uninitialized variable" warnings at -O2
[ Upstream commit adb8049 ] x86_energy_perf_policy first uses __get_cpuid() to check the maximum CPUID level and exits if it is too low. It then assumes that later calls will succeed (which I think is architecturally guaranteed). It also assumes that CPUID works at all (which is not guaranteed on x86_32). If optimisations are enabled, gcc warns about potentially uninitialized variables. Fix this by adding an exit-on-error after every call to __get_cpuid() instead of just checking the maximum level. Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: Len Brown <len.brown@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e9e492c commit edf8ba3

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

‎tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,22 +1259,26 @@ void probe_dev_msr(void)
12591259
if (system("/sbin/modprobe msr > /dev/null 2>&1"))
12601260
err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" ");
12611261
}
1262+
1263+
static void get_cpuid_or_exit(unsigned int leaf,
1264+
unsigned int *eax, unsigned int *ebx,
1265+
unsigned int *ecx, unsigned int *edx)
1266+
{
1267+
if (!__get_cpuid(leaf, eax, ebx, ecx, edx))
1268+
errx(1, "Processor not supported\n");
1269+
}
1270+
12621271
/*
12631272
* early_cpuid()
12641273
* initialize turbo_is_enabled, has_hwp, has_epb
12651274
* before cmdline is parsed
12661275
*/
12671276
void early_cpuid(void)
12681277
{
1269-
unsigned int eax, ebx, ecx, edx, max_level;
1278+
unsigned int eax, ebx, ecx, edx;
12701279
unsigned int fms, family, model;
12711280

1272-
__get_cpuid(0, &max_level, &ebx, &ecx, &edx);
1273-
1274-
if (max_level < 6)
1275-
errx(1, "Processor not supported\n");
1276-
1277-
__get_cpuid(1, &fms, &ebx, &ecx, &edx);
1281+
get_cpuid_or_exit(1, &fms, &ebx, &ecx, &edx);
12781282
family = (fms >> 8) & 0xf;
12791283
model = (fms >> 4) & 0xf;
12801284
if (family == 6 || family == 0xf)
@@ -1288,7 +1292,7 @@ void early_cpuid(void)
12881292
bdx_highest_ratio = msr & 0xFF;
12891293
}
12901294

1291-
__get_cpuid(0x6, &eax, &ebx, &ecx, &edx);
1295+
get_cpuid_or_exit(0x6, &eax, &ebx, &ecx, &edx);
12921296
turbo_is_enabled = (eax >> 1) & 1;
12931297
has_hwp = (eax >> 7) & 1;
12941298
has_epb = (ecx >> 3) & 1;
@@ -1306,7 +1310,7 @@ void parse_cpuid(void)
13061310

13071311
eax = ebx = ecx = edx = 0;
13081312

1309-
__get_cpuid(0, &max_level, &ebx, &ecx, &edx);
1313+
get_cpuid_or_exit(0, &max_level, &ebx, &ecx, &edx);
13101314

13111315
if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e)
13121316
genuine_intel = 1;
@@ -1315,7 +1319,7 @@ void parse_cpuid(void)
13151319
fprintf(stderr, "CPUID(0): %.4s%.4s%.4s ",
13161320
(char *)&ebx, (char *)&edx, (char *)&ecx);
13171321

1318-
__get_cpuid(1, &fms, &ebx, &ecx, &edx);
1322+
get_cpuid_or_exit(1, &fms, &ebx, &ecx, &edx);
13191323
family = (fms >> 8) & 0xf;
13201324
model = (fms >> 4) & 0xf;
13211325
stepping = fms & 0xf;
@@ -1340,7 +1344,7 @@ void parse_cpuid(void)
13401344
errx(1, "CPUID: no MSR");
13411345

13421346

1343-
__get_cpuid(0x6, &eax, &ebx, &ecx, &edx);
1347+
get_cpuid_or_exit(0x6, &eax, &ebx, &ecx, &edx);
13441348
/* turbo_is_enabled already set */
13451349
/* has_hwp already set */
13461350
has_hwp_notify = eax & (1 << 8);

0 commit comments

Comments
 (0)