From d5ff3cd05036928b5df1ca4bdf20e413fdd7b516 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 17 Mar 2022 16:38:35 -0400 Subject: [PATCH] kernel/system_info: Address review comments. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Combine "i" and "firstCPU" iteration variables. * Use better variable names. Change-Id: Ifc6fcaea6519dc4a791600f4a8bcdd38f02434f3 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5111 Tested-by: Commit checker robot Reviewed-by: Adrien Destugues Reviewed-by: Jérôme Duval Reviewed-by: Axel Dörfler --- src/system/kernel/system_info.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/system/kernel/system_info.cpp b/src/system/kernel/system_info.cpp index 332e7282b1..9139a1d642 100644 --- a/src/system/kernel/system_info.cpp +++ b/src/system/kernel/system_info.cpp @@ -521,7 +521,7 @@ _get_cpu_info_etc(uint32 firstCPU, uint32 cpuCount, cpu_info* info, size_t size) if (firstCPU >= (uint32)smp_get_num_cpus()) return B_BAD_VALUE; - uint32 count = std::min(cpuCount, smp_get_num_cpus() - firstCPU); + const uint32 endCPU = firstCPU + std::min(cpuCount, smp_get_num_cpus() - firstCPU); // This function is called very often from userland by applications // that display CPU usage information, so we want to keep this as @@ -529,16 +529,18 @@ _get_cpu_info_etc(uint32 firstCPU, uint32 cpuCount, cpu_info* info, size_t size) // of an allocated temporary buffer. cpu_info localInfo[8]; - for (uint32 i = 0; i < count; ) { - uint32 j; - for (j = 0; i < count && j < B_COUNT_OF(localInfo); i++, j++) { - localInfo[j].active_time = cpu_get_active_time(firstCPU + i); - localInfo[j].enabled = !gCPU[firstCPU + i].disabled; - localInfo[j].current_frequency = cpu_frequency(firstCPU + i); + for (uint32 cpuIdx = firstCPU; cpuIdx < endCPU; ) { + uint32 localIdx; + for (localIdx = 0; cpuIdx < endCPU && localIdx < B_COUNT_OF(localInfo); + cpuIdx++, localIdx++) { + localInfo[localIdx].active_time = cpu_get_active_time(cpuIdx); + localInfo[localIdx].enabled = !gCPU[cpuIdx].disabled; + localInfo[localIdx].current_frequency = cpu_frequency(cpuIdx); } - if (user_memcpy(info + (i - j), localInfo, sizeof(cpu_info) * j) != B_OK) + if (user_memcpy(info, localInfo, sizeof(cpu_info) * localIdx) != B_OK) return B_BAD_ADDRESS; + info += localIdx; } return B_OK;