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 <maheedharsai.bollapalli@amd.com>
diff --git a/plat/xilinx/versal/bl31_versal_setup.c b/plat/xilinx/versal/bl31_versal_setup.c
index 54badf5..befe36c 100644
--- a/plat/xilinx/versal/bl31_versal_setup.c
+++ b/plat/xilinx/versal/bl31_versal_setup.c
@@ -151,16 +151,19 @@
 {
 	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 @@
 
 	index++;
 
-	return 0;
+exit_label:
+	return ret;
 }
 
 static uint64_t rdo_el3_interrupt_handler(uint32_t id, uint32_t flags,
@@ -178,6 +182,7 @@
 	(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 @@
 	}
 
 	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 f160563..b976267 100644
--- a/plat/xilinx/versal/plat_psci.c
+++ b/plat/xilinx/versal/plat_psci.c
@@ -28,16 +28,17 @@
 {
 	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 @@
 	/* 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 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 @@
 
 	/* 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 ba17b1d..6e0b2d6 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_CPU_MASK) >= PLATFORM_CORE_COUNT) {
-		return -1;
+	if (((mpidr & MPIDR_CLUSTER_MASK) == 0U) &&
+	       ((mpidr & MPIDR_CPU_MASK) < PLATFORM_CORE_COUNT)) {
+		ret = versal_calc_core_pos(mpidr);
 	}
 
-	return (int32_t)versal_calc_core_pos(mpidr);
+	return ret;
 }