From 890781d10ce362150359c00b06c8b7e9e1ee34d2 Mon Sep 17 00:00:00 2001 From: Maheedhar Bollapalli Date: Tue, 29 Oct 2024 00:09:08 +0000 Subject: [PATCH] fix(versal): modify function to have single return This corrects the MISRA violation C2012-15.5: A function should have a single point of exit at the end. Introduced a temporary variable to store the return value to ensure single return for the function. Change-Id: Iffbd8770fd4ff2f2176062469d22961cbaa160b4 Signed-off-by: Maheedhar Bollapalli --- plat/xilinx/versal/bl31_versal_setup.c | 15 ++++++++++----- plat/xilinx/versal/plat_psci.c | 15 ++++++++++----- plat/xilinx/versal/plat_versal.c | 13 ++++++------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/plat/xilinx/versal/bl31_versal_setup.c b/plat/xilinx/versal/bl31_versal_setup.c index 54badf511..befe36c65 100644 --- a/plat/xilinx/versal/bl31_versal_setup.c +++ b/plat/xilinx/versal/bl31_versal_setup.c @@ -151,16 +151,19 @@ int request_intr_type_el3(uint32_t id, interrupt_type_handler_t handler) { static uint32_t index; uint32_t i; + int32_t ret = 0; /* Validate 'handler' and 'id' parameters */ if ((handler == NULL) || (index >= MAX_INTR_EL3)) { - return -EINVAL; + ret = -EINVAL; + goto exit_label; } /* Check if a handler has already been registered */ for (i = 0; i < index; i++) { if (id == type_el3_interrupt_table[i].id) { - return -EALREADY; + ret = -EALREADY; + goto exit_label; } } @@ -169,7 +172,8 @@ int request_intr_type_el3(uint32_t id, interrupt_type_handler_t handler) index++; - return 0; +exit_label: + return ret; } static uint64_t rdo_el3_interrupt_handler(uint32_t id, uint32_t flags, @@ -178,6 +182,7 @@ static uint64_t rdo_el3_interrupt_handler(uint32_t id, uint32_t flags, (void)id; uint32_t intr_id; uint32_t i; + uint64_t ret = 0; interrupt_type_handler_t handler = NULL; intr_id = plat_ic_get_pending_interrupt_id(); @@ -189,10 +194,10 @@ static uint64_t rdo_el3_interrupt_handler(uint32_t id, uint32_t flags, } if (handler != NULL) { - return handler(intr_id, flags, handle, cookie); + ret = handler(intr_id, flags, handle, cookie); } - return 0; + return ret; } void bl31_platform_setup(void) diff --git a/plat/xilinx/versal/plat_psci.c b/plat/xilinx/versal/plat_psci.c index f160563bd..b9762675f 100644 --- a/plat/xilinx/versal/plat_psci.c +++ b/plat/xilinx/versal/plat_psci.c @@ -28,16 +28,17 @@ static int32_t versal_pwr_domain_on(u_register_t mpidr) { int32_t cpu_id = plat_core_pos_by_mpidr(mpidr); const struct pm_proc *proc; + int32_t ret = PSCI_E_INTERN_FAIL; VERBOSE("%s: mpidr: 0x%lx\n", __func__, mpidr); if (cpu_id == -1) { - return PSCI_E_INTERN_FAIL; + goto exit_label; } proc = pm_get_proc((uint32_t)cpu_id); if (proc == NULL) { - return PSCI_E_INTERN_FAIL; + goto exit_label; } /* Send request to PMC to wake up selected ACPU core */ @@ -47,7 +48,10 @@ static int32_t versal_pwr_domain_on(u_register_t mpidr) /* Clear power down request */ pm_client_wakeup(proc); - return PSCI_E_SUCCESS; + ret = PSCI_E_SUCCESS; + +exit_label: + return ret; } /** @@ -246,6 +250,7 @@ static void versal_pwr_domain_off(const psci_power_state_t *target_state) static int32_t versal_validate_power_state(uint32_t power_state, psci_power_state_t *req_state) { + int32_t ret = PSCI_E_SUCCESS; VERBOSE("%s: power_state: 0x%x\n", __func__, power_state); uint32_t pstate = psci_get_pstate_type(power_state); @@ -261,10 +266,10 @@ static int32_t versal_validate_power_state(uint32_t power_state, /* We expect the 'state id' to be zero */ if (psci_get_pstate_id(power_state) != 0U) { - return PSCI_E_INVALID_PARAMS; + ret = PSCI_E_INVALID_PARAMS; } - return PSCI_E_SUCCESS; + return ret; } /** diff --git a/plat/xilinx/versal/plat_versal.c b/plat/xilinx/versal/plat_versal.c index ba17b1d9f..6e0b2d65a 100644 --- a/plat/xilinx/versal/plat_versal.c +++ b/plat/xilinx/versal/plat_versal.c @@ -10,13 +10,12 @@ int32_t plat_core_pos_by_mpidr(u_register_t mpidr) { - if ((mpidr & MPIDR_CLUSTER_MASK) != 0U) { - return -1; + int32_t ret = -1; + + if (((mpidr & MPIDR_CLUSTER_MASK) == 0U) && + ((mpidr & MPIDR_CPU_MASK) < PLATFORM_CORE_COUNT)) { + ret = versal_calc_core_pos(mpidr); } - if ((mpidr & MPIDR_CPU_MASK) >= PLATFORM_CORE_COUNT) { - return -1; - } - - return (int32_t)versal_calc_core_pos(mpidr); + return ret; }