board: lx2160a: Add check in GIC RD tables init

Program the GIC redistributor tables only when succeeded to reserve memory
for them, otherwise kernel will lose the chance to program them using
allocated memory.

Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Reviewed-by: Wasim Khan <wasim.khan@nxp.com>
Signed-off-by: Priyanka Jain <priyanka.jain@nxp.com>
diff --git a/board/freescale/lx2160a/lx2160a.c b/board/freescale/lx2160a/lx2160a.c
index 23ea1b6..eafd530 100644
--- a/board/freescale/lx2160a/lx2160a.c
+++ b/board/freescale/lx2160a/lx2160a.c
@@ -645,7 +645,7 @@
 #endif
 
 #ifdef CONFIG_GIC_V3_ITS
-void fdt_fixup_gic_lpi_memory(void *blob, u64 gic_lpi_base)
+int fdt_fixup_gic_lpi_memory(void *blob, u64 gic_lpi_base)
 {
 	u32 phandle;
 	int err;
@@ -656,6 +656,8 @@
 	err = fdtdec_add_reserved_memory(blob, "gic-lpi", &gic_lpi, &phandle);
 	if (err < 0)
 		debug("failed to add reserved memory: %d\n", err);
+
+	return err;
 }
 #endif
 
@@ -671,6 +673,7 @@
 	u64 mc_memory_size = 0;
 	u16 total_memory_banks;
 	u64 __maybe_unused gic_lpi_base;
+	int ret;
 
 	ft_cpu_setup(blob, bd);
 
@@ -692,8 +695,9 @@
 
 #ifdef CONFIG_GIC_V3_ITS
 	gic_lpi_base = gd->arch.resv_ram - GIC_LPI_SIZE;
-	gic_lpi_tables_init(gic_lpi_base, cpu_numcores());
-	fdt_fixup_gic_lpi_memory(blob, gic_lpi_base);
+	ret = fdt_fixup_gic_lpi_memory(blob, gic_lpi_base);
+	if (!ret && gic_lpi_tables_init(gic_lpi_base, cpu_numcores()))
+		debug("%s: failed to init gic-lpi-tables\n", __func__);
 #endif
 
 #ifdef CONFIG_RESV_RAM