1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

RDMSR: Fix minor mistake in msr_serialize_raw_data()

- Allow to set filename as NULL
- Replace printf() by fprintf()
- Use a switch case instead multiple if statements
This commit is contained in:
Xorg 2019-02-17 15:26:44 +01:00
parent 92d3a77105
commit 32d1ac4aff

View file

@ -1021,7 +1021,7 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
if (handle == NULL) if (handle == NULL)
return set_error(ERR_HANDLE); return set_error(ERR_HANDLE);
if (!strcmp(filename, "")) if ((filename == NULL) || !strcmp(filename, ""))
f = stdout; f = stdout;
else else
f = fopen(filename, "wt"); f = fopen(filename, "wt");
@ -1031,22 +1031,21 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
return -1; return -1;
fprintf(f, "CPU is %s %s, stock clock is %dMHz.\n", id.vendor_str, id.brand_str, cpu_clock_measure(250, 1)); fprintf(f, "CPU is %s %s, stock clock is %dMHz.\n", id.vendor_str, id.brand_str, cpu_clock_measure(250, 1));
if (id.vendor == VENDOR_INTEL) switch (id.vendor) {
msr = intel_msr; case VENDOR_AMD: msr = amd_msr; break;
else if (id.vendor == VENDOR_AMD) case VENDOR_INTEL: msr = intel_msr; break;
msr = amd_msr; default: return set_error(ERR_CPU_UNKN);
else }
return set_error(ERR_CPU_UNKN);
for (i = 0; msr[i] != CPU_INVALID_VALUE; i++) { for (i = 0; msr[i] != CPU_INVALID_VALUE; i++) {
cpu_rdmsr(handle, msr[i], &reg); cpu_rdmsr(handle, msr[i], &reg);
fprintf(f, "msr[%#08x]=", msr[i]); fprintf(f, "msr[%#08x]=", msr[i]);
for (j = 56; j >= 0; j -= 8) for (j = 56; j >= 0; j -= 8)
fprintf(f, "%02x ", (int) (reg >> j) & 0xff); fprintf(f, "%02x ", (int) (reg >> j) & 0xff);
printf("\n"); fprintf(f, "\n");
} }
if (strcmp(filename, "")) if ((filename != NULL) && strcmp(filename, ""))
fclose(f); fclose(f);
return set_error(ERR_OK); return set_error(ERR_OK);
} }