mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-23 09:47:44 +00:00
hv: cpu: fix 'Pointer arithmetic is not on array'
Use the array for lapic_id directly to avoid the unnecessary pointer arithmetic. With current implementation, lapic_id_base is always a byte array with CPU_PAGE_SIZE elements What this patch does: - replace 'uint8_t *lapic_id_base' with 'uint8_t lapic_id_array[CPU_PAGE_SIZE]' to make the boundary explicit - add a range check to ensure that there is no overflow v2 -> v3: * update the array size of lapic_id_array per discussion with Fengwei v1 -> v2: * remove the unnecessary range check in parse_madt in cpu.c Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
@@ -221,7 +221,7 @@ void *get_acpi_tbl(const char *sig)
|
||||
return HPA2HVA(addr);
|
||||
}
|
||||
|
||||
static uint16_t _parse_madt(void *madt, uint8_t *lapic_id_base)
|
||||
static uint16_t _parse_madt(void *madt, uint8_t lapic_id_array[MAX_PCPU_NUM])
|
||||
{
|
||||
uint16_t pcpu_id = 0;
|
||||
struct acpi_madt_local_apic *processor;
|
||||
@@ -243,9 +243,16 @@ static uint16_t _parse_madt(void *madt, uint8_t *lapic_id_base)
|
||||
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_base = processor->id;
|
||||
lapic_id_base++;
|
||||
lapic_id_array[pcpu_id] = processor->id;
|
||||
pcpu_id++;
|
||||
/*
|
||||
* set the pcpu_num as 0U to indicate the
|
||||
* potential overflow
|
||||
*/
|
||||
if (pcpu_id >= MAX_PCPU_NUM) {
|
||||
pcpu_id = 0U;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,8 +263,8 @@ static uint16_t _parse_madt(void *madt, uint8_t *lapic_id_base)
|
||||
return pcpu_id;
|
||||
}
|
||||
|
||||
/* The lapic_id info gotten from madt will be returned in lapic_id_base */
|
||||
uint16_t parse_madt(uint8_t *lapic_id_base)
|
||||
/* The lapic_id info gotten from madt will be returned in lapic_id_array */
|
||||
uint16_t parse_madt(uint8_t lapic_id_array[MAX_PCPU_NUM])
|
||||
{
|
||||
void *madt;
|
||||
|
||||
@@ -267,7 +274,7 @@ uint16_t parse_madt(uint8_t *lapic_id_base)
|
||||
madt = get_acpi_tbl(ACPI_SIG_MADT);
|
||||
ASSERT(madt != NULL, "fail to get madt");
|
||||
|
||||
return _parse_madt(madt, lapic_id_base);
|
||||
return _parse_madt(madt, lapic_id_array);
|
||||
}
|
||||
|
||||
void *get_dmar_table(void)
|
||||
|
Reference in New Issue
Block a user