From 0b24bdb73c5ace1b7cd7106d5d4df1c4898a9bce Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Tue, 1 Dec 2020 11:24:16 +0000 Subject: [PATCH] UPSTREAM: arm64: sdei: Push IS_ENABLED() checks down to callee functions Handling all combinations of the VMAP_STACK and SHADOW_CALL_STACK options in sdei_arch_get_entry_point() makes the code difficult to read, particularly when considering the error and cleanup paths. Move the checking of these options into the callee functions, so that they return early if the relevant option is not enabled. Bug: 169781940 Change-Id: I3daf8a409d3544fa4e76a28c2b2ae9efb82001ba (cherry picked from commit eec3bf6861a8703ab63992578b1776353c5ac2a1) Signed-off-by: Will Deacon Signed-off-by: Sami Tolvanen --- arch/arm64/kernel/sdei.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 5e537d5766e9..3f129b40d0db 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -62,6 +62,9 @@ static void free_sdei_stacks(void) { int cpu; + if (!IS_ENABLED(CONFIG_VMAP_STACK)) + return; + for_each_possible_cpu(cpu) { _free_sdei_stack(&sdei_stack_normal_ptr, cpu); _free_sdei_stack(&sdei_stack_critical_ptr, cpu); @@ -85,6 +88,9 @@ static int init_sdei_stacks(void) int cpu; int err = 0; + if (!IS_ENABLED(CONFIG_VMAP_STACK)) + return 0; + for_each_possible_cpu(cpu) { err = _init_sdei_stack(&sdei_stack_normal_ptr, cpu); if (err) @@ -138,6 +144,9 @@ static int init_sdei_scs(void) int cpu; int err = 0; + if (!IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) + return 0; + for_each_possible_cpu(cpu) { err = _init_sdei_scs(&sdei_shadow_call_stack_normal_ptr, cpu); if (err) @@ -193,21 +202,14 @@ unsigned long sdei_arch_get_entry_point(int conduit) */ if (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) { pr_err("Not supported on this hardware/boot configuration\n"); - return 0; + goto out_err; } - if (IS_ENABLED(CONFIG_VMAP_STACK)) { - if (init_sdei_stacks()) - return 0; - } + if (init_sdei_stacks()) + goto out_err; - if (IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) { - if (init_sdei_scs()) { - if (IS_ENABLED(CONFIG_VMAP_STACK)) - free_sdei_stacks(); - return 0; - } - } + if (init_sdei_scs()) + goto out_err_free_stacks; sdei_exit_mode = (conduit == SMCCC_CONDUIT_HVC) ? SDEI_EXIT_HVC : SDEI_EXIT_SMC; @@ -222,6 +224,10 @@ unsigned long sdei_arch_get_entry_point(int conduit) #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ return (unsigned long)__sdei_asm_handler; +out_err_free_stacks: + free_sdei_stacks(); +out_err: + return 0; } /*