1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-20 23:01:51 +00:00

Fix a regression in cpuid_tool when ident_required=0 for arg

In 2b8023f733, I had to update the behavior of cpuid_tool to loop over all data.cpu_types items.
I did not realize since this change, it was not entering the loop for args with ident_required=0, because data.num_cpu_types was always 0, so print_info() was never called for such args.

In other words, args like --rdmsr or --cpuid did nothing due to this regression. This commit fix this regression.
This commit is contained in:
The Tumultuous Unicorn Of Darkness 2024-07-31 16:33:40 +02:00
parent d31e2fd73b
commit b7940c7029
No known key found for this signature in database
GPG key ID: 1E55EE2EFF18BC1A

View file

@ -374,6 +374,13 @@ static void print_info(output_data_switch query, struct cpu_id_t* data)
{ {
int i, value; int i, value;
struct msr_driver_t* handle; struct msr_driver_t* handle;
/* Check if function is properly called */
if ((data == NULL) && check_need_raw_data()) {
fprintf(stderr, "print_info: raw data is required but not provided.\n");
return;
}
switch (query) { switch (query) {
case NEED_CPUID_PRESENT: case NEED_CPUID_PRESENT:
fprintf(fout, "%d\n", cpuid_present()); fprintf(fout, "%d\n", cpuid_present());
@ -859,21 +866,26 @@ int main(int argc, char** argv)
} }
/* OK, process all queries. */ /* OK, process all queries. */
if (((!need_report || !only_clock_queries) && num_requests > 0) || need_identify) { if (((!need_report || !only_clock_queries) && num_requests > 0) || need_identify) {
/* Identify the CPU. Make it do cpuid_get_all_raw_data() itself */ if (check_need_raw_data()) {
if (check_need_raw_data() && cpu_identify_all(&raw_array, &data) < 0) { /* Identify the CPU. Make it do cpuid_get_all_raw_data() itself */
if (!need_quiet) if (cpu_identify_all(&raw_array, &data) < 0) {
fprintf(stderr, if (!need_quiet)
"Error identifying the CPU: %s\n", fprintf(stderr,
cpuid_error()); "Error identifying the CPU: %s\n",
return -1; cpuid_error());
} return -1;
}
for (cpu_type_index = 0; cpu_type_index < data.num_cpu_types; cpu_type_index++) { for (cpu_type_index = 0; cpu_type_index < data.num_cpu_types; cpu_type_index++) {
if (raw_array.with_affinity && (cpu_type_index > 0)) if (raw_array.with_affinity && (cpu_type_index > 0))
fprintf(fout, "--------------------------------------------------------------------------------\n"); fprintf(fout, "--------------------------------------------------------------------------------\n");
for (i = 0; i < num_requests; i++) for (i = 0; i < num_requests; i++)
print_info(requests[i], &data.cpu_types[cpu_type_index]); print_info(requests[i], &data.cpu_types[cpu_type_index]);
}
} }
else
for (i = 0; i < num_requests; i++)
print_info(requests[i], NULL);
} }
if (need_cpulist) { if (need_cpulist) {
print_cpulist(); print_cpulist();