refactor(xilinx): remove multiple return paths in prepare_dtb

presence of multiple return path in prepare_dtb results in misra c
violation 15.5: this return statement is not the final statement
in the compound statement that forms the body of the function.
prepare_dtb is refactored to address the same.

Change-Id: I17ca4314202d6ca8d6fb0c4ea2ed9d31a152371b
Signed-off-by: Amit Nagal <amit.nagal@amd.com>
diff --git a/plat/xilinx/common/plat_fdt.c b/plat/xilinx/common/plat_fdt.c
index 911f664..de5d1a1 100644
--- a/plat/xilinx/common/plat_fdt.c
+++ b/plat/xilinx/common/plat_fdt.c
@@ -15,61 +15,84 @@
 
 void prepare_dtb(void)
 {
+#if defined(XILINX_OF_BOARD_DTB_ADDR)
 	void *dtb;
-	int ret;
-#if !defined(XILINX_OF_BOARD_DTB_ADDR)
-	return;
-#else
+	int map_ret = 0;
+	int ret = 0;
+
 	dtb = (void *)XILINX_OF_BOARD_DTB_ADDR;
-#endif
-	if (IS_TFA_IN_OCM(BL31_BASE))
-		return;
+
+	if (!IS_TFA_IN_OCM(BL31_BASE)) {
 
 #if defined(PLAT_XLAT_TABLES_DYNAMIC)
-	ret = mmap_add_dynamic_region((unsigned long long)dtb,
-				      (uintptr_t)dtb,
-				      XILINX_OF_BOARD_DTB_MAX_SIZE,
-				      MT_MEMORY | MT_RW | MT_NS);
-	if (ret != 0) {
-		WARN("Failed to add dynamic region for dtb: error %d\n", ret);
-		return;
-	}
+		map_ret = mmap_add_dynamic_region((unsigned long long)dtb,
+						 (uintptr_t)dtb,
+						 XILINX_OF_BOARD_DTB_MAX_SIZE,
+						 MT_MEMORY | MT_RW | MT_NS);
+		if (map_ret != 0) {
+			WARN("Failed to add dynamic region for dtb: error %d\n",
+			     map_ret);
+		}
 #endif
 
-	/* Return if no device tree is detected */
-	if (fdt_check_header(dtb) != 0) {
-		NOTICE("Can't read DT at %p\n", dtb);
-		return;
-	}
+		if (!map_ret) {
+			/* Return if no device tree is detected */
+			if (fdt_check_header(dtb) != 0) {
+				NOTICE("Can't read DT at %p\n", dtb);
+			} else {
+				ret = fdt_open_into(dtb, dtb, XILINX_OF_BOARD_DTB_MAX_SIZE);
 
-	ret = fdt_open_into(dtb, dtb, XILINX_OF_BOARD_DTB_MAX_SIZE);
-	if (ret < 0) {
-		ERROR("Invalid Device Tree at %p: error %d\n", dtb, ret);
-		return;
-	}
+				if (ret < 0) {
+					ERROR("Invalid Device Tree at %p: error %d\n",
+					      dtb, ret);
+				} else {
 
-	/* Reserve memory used by Trusted Firmware. */
-	if (fdt_add_reserved_memory(dtb, "tf-a", BL31_BASE, BL31_LIMIT - BL31_BASE)) {
-		WARN("Failed to add reserved memory nodes for BL31 to DT.\n");
-		return;
-	}
+					if (dt_add_psci_node(dtb)) {
+						WARN("Failed to add PSCI Device Tree node\n");
+					}
 
-	ret = fdt_pack(dtb);
-	if (ret < 0) {
-		ERROR("Failed to pack Device Tree at %p: error %d\n", dtb, ret);
-		return;
-	}
+					if (dt_add_psci_cpu_enable_methods(dtb)) {
+						WARN("Failed to add PSCI cpu enable methods in DT\n");
+					}
 
-	flush_dcache_range((uintptr_t)dtb, fdt_blob_size(dtb));
+					/* Reserve memory used by Trusted Firmware. */
+					ret = fdt_add_reserved_memory(dtb,
+								     "tf-a",
+								     BL31_BASE,
+								     BL31_LIMIT
+								     -
+								     BL31_BASE);
+					if (ret < 0) {
+						WARN("Failed to add reserved memory nodes for BL31 to DT.\n");
+					}
+
+					ret = fdt_pack(dtb);
+					if (ret < 0) {
+						WARN("Failed to pack dtb at %p: error %d\n",
+						     dtb, ret);
+					}
+					flush_dcache_range((uintptr_t)dtb,
+							   fdt_blob_size(dtb));
+
+					INFO("Changed device tree to advertise PSCI and reserved memories.\n");
+
+				}
+			}
+
+		}
+
 
 #if defined(PLAT_XLAT_TABLES_DYNAMIC)
-	ret = mmap_remove_dynamic_region((uintptr_t)dtb,
+		if (!map_ret) {
+			ret = mmap_remove_dynamic_region((uintptr_t)dtb,
 					 XILINX_OF_BOARD_DTB_MAX_SIZE);
-	if (ret != 0) {
-		WARN("Failed to remove dynamic region for dtb: error %d\n", ret);
-		return;
-	}
+			if (ret != 0) {
+				WARN("Failed to remove dynamic region for dtb:error %d\n",
+					ret);
+			}
+		}
 #endif
+	}
 
-	INFO("Changed device tree to advertise PSCI and reserved memories.\n");
+#endif
 }