From afc16dfac09f201a2f8192edfbda861913e7dafe Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Wed, 11 Mar 2020 09:29:21 -0700 Subject: [PATCH] arm64: Fix section mismatch with LTO caused by ambiguous const Due to how dt_supported_cpu_ops and acpi_supported_cpu_ops are used, they can be placed in a different section by the compiler when LTO is used because it thinks that it belongs in another section. To really make it clear to GCC that these belong in the __initconst section, make the variables themselves const and refactor cpu_get_ops() accordingly to make it compile. Signed-off-by: Sultan Alsawaf Signed-off-by: Yousef Algadri Signed-off-by: Panchajanya Sarkar Signed-off-by: UtsavBalar1231 --- arch/arm64/kernel/cpu_ops.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c index e2a9d04d0517..d9a34e77cfa7 100644 --- a/arch/arm64/kernel/cpu_ops.c +++ b/arch/arm64/kernel/cpu_ops.c @@ -31,13 +31,13 @@ extern const struct cpu_operations cpu_psci_ops; const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init; -static const struct cpu_operations *dt_supported_cpu_ops[] __initconst = { +static const struct cpu_operations *const dt_supported_cpu_ops[] __initconst = { &smp_spin_table_ops, &cpu_psci_ops, NULL, }; -static const struct cpu_operations *acpi_supported_cpu_ops[] __initconst = { +static const struct cpu_operations *const acpi_supported_cpu_ops[] __initconst = { #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL &acpi_parking_protocol_ops, #endif @@ -47,15 +47,18 @@ static const struct cpu_operations *acpi_supported_cpu_ops[] __initconst = { static const struct cpu_operations * __init cpu_get_ops(const char *name) { - const struct cpu_operations **ops; + int i; - ops = acpi_disabled ? dt_supported_cpu_ops : acpi_supported_cpu_ops; - - while (*ops) { - if (!strcmp(name, (*ops)->name)) - return *ops; - - ops++; + if (acpi_disabled) { + for (i = 0; i < ARRAY_SIZE(dt_supported_cpu_ops); i++) { + if (!strcmp(name, dt_supported_cpu_ops[i]->name)) + return dt_supported_cpu_ops[i]; + } + } else { + for (i = 0; i < ARRAY_SIZE(acpi_supported_cpu_ops); i++) { + if (!strcmp(name, acpi_supported_cpu_ops[i]->name)) + return acpi_supported_cpu_ops[i]; + } } return NULL;