diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 6653823a3..c5846a85c 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -308,7 +308,7 @@ static void init_percpu_data_area(void) alloc_phy_cpu_data(pcpu_num); - for (i = 0U; i < pcpu_num; i++) { + for (i = 0U; (i < pcpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) { per_cpu(lapic_id, i) = lapic_id_array[i]; } } @@ -592,7 +592,7 @@ static uint16_t get_cpu_id_from_lapic_id(uint32_t lapic_id) { uint16_t i; - for (i = 0U; i < phys_cpu_num; i++) { + for (i = 0U; (i < phys_cpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) { if (per_cpu(lapic_id, i) == lapic_id) { return i; } diff --git a/hypervisor/boot/acpi.c b/hypervisor/boot/acpi.c index 046a03da6..34f4ae939 100644 --- a/hypervisor/boot/acpi.c +++ b/hypervisor/boot/acpi.c @@ -229,7 +229,7 @@ static void *get_acpi_tbl(const char *sig) static uint16_t local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM]) { - uint16_t pcpu_id = 0U; + uint16_t pcpu_num = 0U; struct acpi_madt_local_apic *processor; struct acpi_table_madt *madt_ptr; void *first; @@ -249,16 +249,10 @@ local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM]) if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) { processor = (struct acpi_madt_local_apic *)entry; if ((processor->lapic_flags & ACPI_MADT_ENABLED) != 0U) { - lapic_id_array[pcpu_id] = processor->id; - pcpu_id++; - /* - * set the pcpu_num as 0U to indicate the - * potential overflow - */ - if (pcpu_id >= CONFIG_MAX_PCPU_NUM) { - pcpu_id = 0U; - break; + if (pcpu_num < CONFIG_MAX_PCPU_NUM) { + lapic_id_array[pcpu_num] = processor->id; } + pcpu_num++; } } @@ -266,7 +260,7 @@ local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM]) (((uint64_t)entry) + entry->length); } - return pcpu_id; + return pcpu_num; } /* The lapic_id info gotten from madt will be returned in lapic_id_array */ diff --git a/hypervisor/debug/logmsg.c b/hypervisor/debug/logmsg.c index 0eea0952f..1ae8085cb 100644 --- a/hypervisor/debug/logmsg.c +++ b/hypervisor/debug/logmsg.c @@ -77,7 +77,7 @@ void init_logmsg(uint32_t flags) logmsg.seq = 0; /* allocate sbuf for log before sos booting */ - for (pcpu_id = 0U; pcpu_id < phys_cpu_num; pcpu_id++) { + for (pcpu_id = 0U; (pcpu_id < phys_cpu_num) && (pcpu_id < CONFIG_MAX_PCPU_NUM); pcpu_id++) { alloc_earlylog_sbuf(pcpu_id); } }