From b7940c702992dc464bb62b5c3ce76edeeaeb6f20 Mon Sep 17 00:00:00 2001 From: The Tumultuous Unicorn Of Darkness Date: Wed, 31 Jul 2024 16:33:40 +0200 Subject: [PATCH] Fix a regression in cpuid_tool when ident_required=0 for arg In 2b8023f7336fc4c66d23fb7c65caee5b3581237e, 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. --- cpuid_tool/cpuid_tool.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/cpuid_tool/cpuid_tool.c b/cpuid_tool/cpuid_tool.c index f7ec9c1..3c4b35f 100644 --- a/cpuid_tool/cpuid_tool.c +++ b/cpuid_tool/cpuid_tool.c @@ -374,6 +374,13 @@ static void print_info(output_data_switch query, struct cpu_id_t* data) { int i, value; 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) { case NEED_CPUID_PRESENT: fprintf(fout, "%d\n", cpuid_present()); @@ -859,21 +866,26 @@ int main(int argc, char** argv) } /* OK, process all queries. */ 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() && cpu_identify_all(&raw_array, &data) < 0) { - if (!need_quiet) - fprintf(stderr, - "Error identifying the CPU: %s\n", - cpuid_error()); - return -1; - } + if (check_need_raw_data()) { + /* Identify the CPU. Make it do cpuid_get_all_raw_data() itself */ + if (cpu_identify_all(&raw_array, &data) < 0) { + if (!need_quiet) + fprintf(stderr, + "Error identifying the CPU: %s\n", + cpuid_error()); + return -1; + } - for (cpu_type_index = 0; cpu_type_index < data.num_cpu_types; cpu_type_index++) { - if (raw_array.with_affinity && (cpu_type_index > 0)) - fprintf(fout, "--------------------------------------------------------------------------------\n"); - for (i = 0; i < num_requests; i++) - print_info(requests[i], &data.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)) + fprintf(fout, "--------------------------------------------------------------------------------\n"); + for (i = 0; i < num_requests; i++) + 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) { print_cpulist();