[U-Boot] [PATCH] arm64: zynqmp: Simplify boot_target variable composition

Michal Simek michal.simek at xilinx.com
Wed Apr 25 12:35:00 UTC 2018


Call calloc for space allocation only at one location and include if/else
to sprintf. This will simplify run time device adding based on id aliases.

Signed-off-by: Michal Simek <michal.simek at xilinx.com>
---

 board/xilinx/zynqmp/zynqmp.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 6d09a4c73139..f7fe1fdfff7b 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -454,6 +454,7 @@ int board_late_init(void)
 {
 	u32 reg = 0;
 	u8 bootmode;
+	int env_targets_len = 0;
 	const char *mode;
 	char *new_targets;
 	char *env_targets;
@@ -530,14 +531,13 @@ int board_late_init(void)
 	 * and default boot_targets
 	 */
 	env_targets = env_get("boot_targets");
-	if (env_targets) {
-		new_targets = calloc(1, strlen(mode) +
-				     strlen(env_targets) + 2);
-		sprintf(new_targets, "%s %s", mode, env_targets);
-	} else {
-		new_targets = calloc(1, strlen(mode) + 2);
-		sprintf(new_targets, "%s", mode);
-	}
+	if (env_targets)
+		env_targets_len = strlen(env_targets);
+
+	new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
+
+	sprintf(new_targets, "%s %s", mode,
+		env_targets ? env_targets : "");
 
 	env_set("boot_targets", new_targets);
 
-- 
2.17.0



More information about the U-Boot mailing list