From 673f4e45fff6de494a2a8c4044f0c1ca7c463728 Mon Sep 17 00:00:00 2001 From: The Tumultuous Unicorn Of Darkness Date: Sun, 4 Aug 2024 15:11:15 +0200 Subject: [PATCH] Improve error handling in cpu_identify_all() --- libcpuid/cpuid_main.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libcpuid/cpuid_main.c b/libcpuid/cpuid_main.c index 1000044..1168564 100644 --- a/libcpuid/cpuid_main.c +++ b/libcpuid/cpuid_main.c @@ -1653,8 +1653,7 @@ static void update_cache_instances(struct internal_cache_instances_t* caches, int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t* system) { - int cur_error = cpuid_set_error(ERR_OK); - int ret_error = cpuid_set_error(ERR_OK); + int r = ERR_OK; double smt_divisor; bool is_smt_supported; bool is_topology_supported = true; @@ -1672,8 +1671,8 @@ int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t* if (system == NULL) return cpuid_set_error(ERR_HANDLE); if (!raw_array) { - if ((ret_error = cpuid_get_all_raw_data(&my_raw_array)) < 0) - return cpuid_set_error(ret_error); + if ((r = cpuid_get_all_raw_data(&my_raw_array)) < 0) + return r; raw_array = &my_raw_array; } system_id_t_constructor(system); @@ -1703,10 +1702,9 @@ int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t* cpu_type_index = system->num_cpu_types; cpuid_grow_system_id(system, system->num_cpu_types + 1); cpuid_grow_type_info(&type_info, type_info.num + 1); - cur_error = cpu_ident_internal(&raw_array->raw[logical_cpu], &system->cpu_types[cpu_type_index], &type_info.data[cpu_type_index].id_info); + if ((r = cpu_ident_internal(&raw_array->raw[logical_cpu], &system->cpu_types[cpu_type_index], &type_info.data[cpu_type_index].id_info)) != ERR_OK) + return r; type_info.data[cpu_type_index].purpose = purpose; - if (ret_error == ERR_OK) - ret_error = cur_error; if (is_topology_supported) type_info.data[cpu_type_index].package_id = cur_package_id; if (raw_array->with_affinity) @@ -1759,7 +1757,7 @@ int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t* system->l4_total_instances = caches_all.instances[L4]; } - return ret_error; + return cpuid_set_error(ERR_OK); } int cpu_request_core_type(cpu_purpose_t purpose, struct cpu_raw_data_array_t* raw_array, struct cpu_id_t* data)