#ifdef CONFIG_X86_LOCAL_APIC
 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
+static bool has_lapic_cpus __initdata;
 static bool acpi_support_online_capable;
 #endif
 
        if (!acpi_is_processor_usable(processor->lapic_flags))
                return 0;
 
+       /*
+        * According to https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#processor-local-x2apic-structure
+        * when MADT provides both valid LAPIC and x2APIC entries, the APIC ID
+        * in x2APIC must be equal or greater than 0xff.
+        */
+       if (has_lapic_cpus && apic_id < 0xff)
+               return 0;
+
        /*
         * We need to register disabled CPU as well to permit
         * counting disabled CPUs. This allows us to size
 
 static int __init acpi_parse_madt_lapic_entries(void)
 {
-       int count;
-       int x2count = 0;
-       int ret;
-       struct acpi_subtable_proc madt_proc[2];
+       int count, x2count = 0;
 
        if (!boot_cpu_has(X86_FEATURE_APIC))
                return -ENODEV;
                                      acpi_parse_sapic, MAX_LOCAL_APIC);
 
        if (!count) {
-               memset(madt_proc, 0, sizeof(madt_proc));
-               madt_proc[0].id = ACPI_MADT_TYPE_LOCAL_APIC;
-               madt_proc[0].handler = acpi_parse_lapic;
-               madt_proc[1].id = ACPI_MADT_TYPE_LOCAL_X2APIC;
-               madt_proc[1].handler = acpi_parse_x2apic;
-               ret = acpi_table_parse_entries_array(ACPI_SIG_MADT,
-                               sizeof(struct acpi_table_madt),
-                               madt_proc, ARRAY_SIZE(madt_proc), MAX_LOCAL_APIC);
-               if (ret < 0) {
-                       pr_err("Error parsing LAPIC/X2APIC entries\n");
-                       return ret;
-               }
-
-               count = madt_proc[0].count;
-               x2count = madt_proc[1].count;
+               count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
+                                       acpi_parse_lapic, MAX_LOCAL_APIC);
+               has_lapic_cpus = count > 0;
+               x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
+                                       acpi_parse_x2apic, MAX_LOCAL_APIC);
        }
        if (!count && !x2count) {
                pr_err("No LAPIC entries present\n");