Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

RISC-V: ACPI: Add acpi_get_cpu_uid() for unified ACPI CPU UID retrieval

As a step towards unifying the interface for retrieving ACPI CPU UID
across architectures, introduce a new function acpi_get_cpu_uid() for
riscv. While at it, add input validation to make the code more robust.

And also update acpi_numa.c and rhct.c to use the new interface instead
of the legacy get_acpi_id_for_cpu().

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/20260401081640.26875-4-fengchengwen@huawei.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Chengwen Feng and committed by
Rafael J. Wysocki
0c823199 d78ef9d2

+29 -4
+1
arch/riscv/include/asm/acpi.h
··· 65 65 { 66 66 return acpi_cpu_get_madt_rintc(cpu)->uid; 67 67 } 68 + int acpi_get_cpu_uid(unsigned int cpu, u32 *uid); 68 69 69 70 int acpi_get_riscv_isa(struct acpi_table_header *table, 70 71 unsigned int cpu, const char **isa);
+16
arch/riscv/kernel/acpi.c
··· 337 337 } 338 338 339 339 #endif /* CONFIG_PCI */ 340 + 341 + int acpi_get_cpu_uid(unsigned int cpu, u32 *uid) 342 + { 343 + struct acpi_madt_rintc *rintc; 344 + 345 + if (cpu >= nr_cpu_ids) 346 + return -EINVAL; 347 + 348 + rintc = acpi_cpu_get_madt_rintc(cpu); 349 + if (!rintc) 350 + return -ENODEV; 351 + 352 + *uid = rintc->uid; 353 + return 0; 354 + } 355 + EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
+6 -3
arch/riscv/kernel/acpi_numa.c
··· 37 37 38 38 static inline int get_cpu_for_acpi_id(u32 uid) 39 39 { 40 - int cpu; 40 + u32 cpu_uid; 41 + int ret; 41 42 42 - for (cpu = 0; cpu < nr_cpu_ids; cpu++) 43 - if (uid == get_acpi_id_for_cpu(cpu)) 43 + for (int cpu = 0; cpu < nr_cpu_ids; cpu++) { 44 + ret = acpi_get_cpu_uid(cpu, &cpu_uid); 45 + if (ret == 0 && uid == cpu_uid) 44 46 return cpu; 47 + } 45 48 46 49 return -EINVAL; 47 50 }
+6 -1
drivers/acpi/riscv/rhct.c
··· 44 44 struct acpi_rhct_isa_string *isa_node; 45 45 struct acpi_table_rhct *rhct; 46 46 u32 *hart_info_node_offset; 47 - u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu); 47 + u32 acpi_cpu_id; 48 + int ret; 48 49 49 50 BUG_ON(acpi_disabled); 51 + 52 + ret = acpi_get_cpu_uid(cpu, &acpi_cpu_id); 53 + if (ret != 0) 54 + return ret; 50 55 51 56 if (!table) { 52 57 rhct = acpi_get_rhct();