From 906d58927760c70112fd8e70a7e67f2a4989e9ed Mon Sep 17 00:00:00 2001 From: Nithin G Date: Thu, 25 Apr 2024 19:10:06 +0530 Subject: [PATCH] fix(xilinx): 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: Ice3eb939664ffc62c1f586b641e37481f10ffff6 Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- plat/xilinx/common/plat_startup.c | 20 ++++--- plat/xilinx/common/pm_service/pm_api_sys.c | 60 ++++++++++++++------- plat/xilinx/common/pm_service/pm_ipi.c | 7 ++- plat/xilinx/common/pm_service/pm_svc_main.c | 23 ++++---- plat/xilinx/common/versal.c | 9 +++- 5 files changed, 78 insertions(+), 41 deletions(-) diff --git a/plat/xilinx/common/plat_startup.c b/plat/xilinx/common/plat_startup.c index 9f829c9f6..c5c52a881 100644 --- a/plat/xilinx/common/plat_startup.c +++ b/plat/xilinx/common/plat_startup.c @@ -123,14 +123,17 @@ static uint32_t get_xbl_ss(const struct xbl_partition *partition) static uint32_t get_xbl_endian(const struct xbl_partition *partition) { uint64_t flags = partition->flags & XBL_FLAGS_ENDIAN_MASK; + uint32_t spsr_value = 0U; flags >>= XBL_FLAGS_ENDIAN_SHIFT; if (flags == XBL_FLAGS_ENDIAN_BE) { - return SPSR_E_BIG; + spsr_value = SPSR_E_BIG; } else { - return SPSR_E_LITTLE; + spsr_value = SPSR_E_LITTLE; } + + return spsr_value; } /** @@ -182,10 +185,12 @@ enum xbl_handoff xbl_handover(entry_point_info_t *bl32, uint64_t handoff_addr) { const struct xbl_handoff_params *HandoffParams; + enum xbl_handoff xbl_status = XBL_HANDOFF_SUCCESS; if (handoff_addr == 0U) { WARN("BL31: No handoff structure passed\n"); - return XBL_HANDOFF_NO_STRUCT; + xbl_status = XBL_HANDOFF_NO_STRUCT; + goto exit_label; } HandoffParams = (struct xbl_handoff_params *)handoff_addr; @@ -194,7 +199,8 @@ enum xbl_handoff xbl_handover(entry_point_info_t *bl32, (HandoffParams->magic[2] != (uint8_t)'N') || (HandoffParams->magic[3] != (uint8_t)'X')) { ERROR("BL31: invalid handoff structure at %" PRIx64 "\n", handoff_addr); - return XBL_HANDOFF_INVAL_STRUCT; + xbl_status = XBL_HANDOFF_INVAL_STRUCT; + goto exit_label; } VERBOSE("BL31: TF-A handoff params at:0x%" PRIx64 ", entries:%u\n", @@ -202,7 +208,8 @@ enum xbl_handoff xbl_handover(entry_point_info_t *bl32, if (HandoffParams->num_entries > XBL_MAX_PARTITIONS) { ERROR("BL31: TF-A handoff params: too many partitions (%u/%u)\n", HandoffParams->num_entries, XBL_MAX_PARTITIONS); - return XBL_HANDOFF_TOO_MANY_PARTS; + xbl_status = XBL_HANDOFF_TOO_MANY_PARTS; + goto exit_label; } /* @@ -304,5 +311,6 @@ enum xbl_handoff xbl_handover(entry_point_info_t *bl32, } } - return XBL_HANDOFF_SUCCESS; +exit_label: + return xbl_status; } diff --git a/plat/xilinx/common/pm_service/pm_api_sys.c b/plat/xilinx/common/pm_service/pm_api_sys.c index 627266d7b..9af8bb264 100644 --- a/plat/xilinx/common/pm_service/pm_api_sys.c +++ b/plat/xilinx/common/pm_service/pm_api_sys.c @@ -149,10 +149,11 @@ enum pm_ret_status pm_self_suspend(uint32_t nid, uint32_t payload[PAYLOAD_ARG_CNT]; uint32_t cpuid = plat_my_core_pos(); const struct pm_proc *proc = pm_get_proc(cpuid); + enum pm_ret_status ret = PM_RET_ERROR_INTERNAL; if (proc == NULL) { WARN("Failed to get proc %d\n", cpuid); - return PM_RET_ERROR_INTERNAL; + goto exit_label; } /* @@ -165,7 +166,10 @@ enum pm_ret_status pm_self_suspend(uint32_t nid, PM_PACK_PAYLOAD6(payload, LIBPM_MODULE_ID, flag, PM_SELF_SUSPEND, proc->node_id, latency, state, address, (address >> 32)); - return pm_ipi_send_sync(proc, payload, NULL, 0); + ret = pm_ipi_send_sync(proc, payload, NULL, 0); + +exit_label: + return ret; } /** @@ -215,15 +219,18 @@ enum pm_ret_status pm_req_suspend(uint32_t target, uint8_t ack, uint32_t flag) { uint32_t payload[PAYLOAD_ARG_CNT]; + enum pm_ret_status ret = PM_RET_SUCCESS; /* Send request to the PMU */ PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_REQ_SUSPEND, target, latency, state); if (ack == (uint32_t)IPI_BLOCKING) { - return pm_ipi_send_sync(primary_proc, payload, NULL, 0); + ret = pm_ipi_send_sync(primary_proc, payload, NULL, 0); } else { - return pm_ipi_send(primary_proc, payload); + ret = pm_ipi_send(primary_proc, payload); } + + return ret; } /** @@ -273,15 +280,15 @@ enum pm_ret_status pm_req_wakeup(uint32_t target, uint32_t set_address, enum pm_ret_status pm_get_callbackdata(uint32_t *data, size_t count, uint32_t flag, uint32_t ack) { enum pm_ret_status ret = PM_RET_SUCCESS; + /* Return if interrupt is not from PMU */ - if (pm_ipi_irq_status(primary_proc) == 0U) { - return ret; - } + if (pm_ipi_irq_status(primary_proc) != 0U) { - ret = pm_ipi_buff_read_callb(data, count); + ret = pm_ipi_buff_read_callb(data, count); - if (ack != 0U) { - pm_ipi_irq_clear(primary_proc); + if (ack != 0U) { + pm_ipi_irq_clear(primary_proc); + } } return ret; @@ -302,16 +309,19 @@ enum pm_ret_status pm_force_powerdown(uint32_t target, uint8_t ack, uint32_t flag) { uint32_t payload[PAYLOAD_ARG_CNT]; + enum pm_ret_status ret = PM_RET_SUCCESS; /* Send request to the PMC */ PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_FORCE_POWERDOWN, target, ack); if (ack == (uint32_t)IPI_BLOCKING) { - return pm_ipi_send_sync(primary_proc, payload, NULL, 0); + ret = pm_ipi_send_sync(primary_proc, payload, NULL, 0); } else { - return pm_ipi_send(primary_proc, payload); + ret = pm_ipi_send(primary_proc, payload); } + + return ret; } /** @@ -328,18 +338,22 @@ enum pm_ret_status pm_system_shutdown(uint32_t type, uint32_t subtype, uint32_t flag) { uint32_t payload[PAYLOAD_ARG_CNT]; + enum pm_ret_status ret = PM_RET_SUCCESS; if (type == XPM_SHUTDOWN_TYPE_SETSCOPE_ONLY) { /* Setting scope for subsequent PSCI reboot or shutdown */ pm_shutdown_scope = subtype; - return PM_RET_SUCCESS; + goto exit_label; } /* Send request to the PMC */ PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SYSTEM_SHUTDOWN, type, subtype); - return pm_ipi_send_non_blocking(primary_proc, payload); + ret = pm_ipi_send_non_blocking(primary_proc, payload); + +exit_label: + return ret; } /** @@ -412,16 +426,19 @@ enum pm_ret_status pm_feature_check(uint32_t api_id, uint32_t *ret_payload, { uint32_t payload[PAYLOAD_ARG_CNT]; uint32_t module_id; + enum pm_ret_status ret; /* Return version of API which are implemented in TF-A only */ switch (api_id) { case PM_GET_CALLBACK_DATA: case PM_GET_TRUSTZONE_VERSION: ret_payload[0] = PM_API_VERSION_2; - return PM_RET_SUCCESS; + ret = PM_RET_SUCCESS; + goto exit_label; case TF_A_PM_REGISTER_SGI: ret_payload[0] = PM_API_BASE_VERSION; - return PM_RET_SUCCESS; + ret = PM_RET_SUCCESS; + goto exit_label; default: break; } @@ -433,12 +450,17 @@ enum pm_ret_status pm_feature_check(uint32_t api_id, uint32_t *ret_payload, * If module_id is 0, then we consider it LIBPM module as default id */ if ((module_id > 0U) && (module_id != LIBPM_MODULE_ID)) { - return PM_RET_SUCCESS; + ret = PM_RET_SUCCESS; + goto exit_label; } PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, - PM_FEATURE_CHECK, api_id); - return pm_ipi_send_sync(primary_proc, payload, ret_payload, RET_PAYLOAD_ARG_CNT); + PM_FEATURE_CHECK, api_id); + ret = pm_ipi_send_sync(primary_proc, payload, ret_payload, RET_PAYLOAD_ARG_CNT); + +exit_label: + return ret; + } /** diff --git a/plat/xilinx/common/pm_service/pm_ipi.c b/plat/xilinx/common/pm_service/pm_ipi.c index e12e74d80..bf1fd550a 100644 --- a/plat/xilinx/common/pm_service/pm_ipi.c +++ b/plat/xilinx/common/pm_service/pm_ipi.c @@ -294,14 +294,17 @@ void pm_ipi_irq_clear(const struct pm_proc *proc) uint32_t pm_ipi_irq_status(const struct pm_proc *proc) { int32_t ret; + int32_t result = 0; ret = ipi_mb_enquire_status(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id); if (((uint32_t)ret & IPI_MB_STATUS_RECV_PENDING) != 0U) { - return 1; + result = 1; } else { - return 0; + result = 0; } + + return result; } #if IPI_CRC_CHECK diff --git a/plat/xilinx/common/pm_service/pm_svc_main.c b/plat/xilinx/common/pm_service/pm_svc_main.c index fe496f3e7..f864700cc 100644 --- a/plat/xilinx/common/pm_service/pm_svc_main.c +++ b/plat/xilinx/common/pm_service/pm_svc_main.c @@ -154,7 +154,7 @@ static uint64_t ipi_fiq_handler(uint32_t id, uint32_t flags, void *handle, ipi_status = ipi_mb_enquire_status(IPI_ID_APU, IPI_ID_PMC); if (((uint32_t)ipi_status & IPI_MB_STATUS_RECV_PENDING) == 0U) { plat_ic_end_of_interrupt(id); - return 0; + goto exit_label; } /* Handle PMC case */ @@ -201,6 +201,7 @@ static uint64_t ipi_fiq_handler(uint32_t id, uint32_t flags, void *handle, /* Clear FIQ */ plat_ic_end_of_interrupt(id); +exit_label: return 0; } @@ -218,21 +219,19 @@ static uint64_t ipi_fiq_handler(uint32_t id, uint32_t flags, void *handle, */ int32_t pm_register_sgi(uint32_t sgi_num, uint32_t reset) { + int32_t ret = 0; + if (reset == 1U) { sgi = INVALID_SGI; - return 0; + } else if (sgi != INVALID_SGI) { + ret = -EBUSY; + } else if (sgi_num >= GICV3_MAX_SGI_TARGETS) { + ret = -EINVAL; + } else { + sgi = (uint32_t)sgi_num; } - if (sgi != INVALID_SGI) { - return -EBUSY; - } - - if (sgi_num >= GICV3_MAX_SGI_TARGETS) { - return -EINVAL; - } - - sgi = (uint32_t)sgi_num; - return 0; + return ret; } /** diff --git a/plat/xilinx/common/versal.c b/plat/xilinx/common/versal.c index 7c29bae33..dc0ae1042 100644 --- a/plat/xilinx/common/versal.c +++ b/plat/xilinx/common/versal.c @@ -25,12 +25,17 @@ */ int32_t plat_is_smccc_feature_available(u_register_t fid) { + int32_t ret = 0; + switch (fid) { case SMCCC_ARCH_SOC_ID: - return SMC_ARCH_CALL_SUCCESS; + ret = SMC_ARCH_CALL_SUCCESS; + break; default: - return SMC_ARCH_CALL_NOT_SUPPORTED; + ret = SMC_ARCH_CALL_NOT_SUPPORTED; } + + return ret; } /**