Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adb80490 authored by Ben Hutchings's avatar Ben Hutchings Committed by Len Brown
Browse files

tools/power x86_energy_perf_policy: Fix "uninitialized variable" warnings at -O2



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: default avatarBen Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent a55aa89a
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -1259,6 +1259,15 @@ void probe_dev_msr(void)
		if (system("/sbin/modprobe msr > /dev/null 2>&1"))
			err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" ");
}

static void get_cpuid_or_exit(unsigned int leaf,
			     unsigned int *eax, unsigned int *ebx,
			     unsigned int *ecx, unsigned int *edx)
{
	if (!__get_cpuid(leaf, eax, ebx, ecx, edx))
		errx(1, "Processor not supported\n");
}

/*
 * early_cpuid()
 * initialize turbo_is_enabled, has_hwp, has_epb
@@ -1266,15 +1275,10 @@ void probe_dev_msr(void)
 */
void early_cpuid(void)
{
	unsigned int eax, ebx, ecx, edx, max_level;
	unsigned int eax, ebx, ecx, edx;
	unsigned int fms, family, model;

	__get_cpuid(0, &max_level, &ebx, &ecx, &edx);

	if (max_level < 6)
		errx(1, "Processor not supported\n");

	__get_cpuid(1, &fms, &ebx, &ecx, &edx);
	get_cpuid_or_exit(1, &fms, &ebx, &ecx, &edx);
	family = (fms >> 8) & 0xf;
	model = (fms >> 4) & 0xf;
	if (family == 6 || family == 0xf)
@@ -1288,7 +1292,7 @@ void early_cpuid(void)
		bdx_highest_ratio = msr & 0xFF;
	}

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

	eax = ebx = ecx = edx = 0;

	__get_cpuid(0, &max_level, &ebx, &ecx, &edx);
	get_cpuid_or_exit(0, &max_level, &ebx, &ecx, &edx);

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

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


	__get_cpuid(0x6, &eax, &ebx, &ecx, &edx);
	get_cpuid_or_exit(0x6, &eax, &ebx, &ecx, &edx);
	/* turbo_is_enabled already set */
	/* has_hwp already set */
	has_hwp_notify = eax & (1 << 8);