[PATCH] LoongArch: acpi: Conditional apic_id vs CONFIG_NR_CPUS comparison

From: WangYuli
Date: Wed Feb 19 2025 - 06:55:52 EST


The apic_id here, as declared as a u8 (unsigned char) in struct
acpi_srat_cpu_affinity of acpi/actbl3.h, has a range up to 255.

Evidently, if CONFIG_NR_CPUS becomes 256 or more, the check
"apic_id >= CONFIG_NR_CPUS" will always be false, which will produce
a compiler warning.

Only compile this code if CONFIG_NR_CPUS is at most 255 consequently.

Fix follow error with clang-18 when W=1e:

arch/loongarch/kernel/acpi.c:302:18: error: result of comparison of constant 256 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
302 | if (pa->apic_id >= CONFIG_NR_CPUS) {
| ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
1 error generated.

Signed-off-by: Yuli Wang <wangyuli@xxxxxxxxxxxxx>
---
arch/loongarch/kernel/acpi.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/arch/loongarch/kernel/acpi.c b/arch/loongarch/kernel/acpi.c
index 2bb3bc42e6ed..ee471a80763e 100644
--- a/arch/loongarch/kernel/acpi.c
+++ b/arch/loongarch/kernel/acpi.c
@@ -299,11 +299,17 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
return;
}

+/*
+ * apic_id's type is u8.
+ * Conditionally skip this check to silence compiler warnings.
+ */
+#if CONFIG_NR_CPUS < 256
if (pa->apic_id >= CONFIG_NR_CPUS) {
pr_info("SRAT: PXM %u -> CPU 0x%02x -> Node %u skipped apicid that is too big\n",
pxm, pa->apic_id, node);
return;
}
+#endif /* CONFIG_NR_CPUS < 256 */

early_numa_add_cpu(pa->apic_id, node);

--
2.47.2