[Concept,19/32] boot: pxe: Use early return in label_load_fdt()

Message ID 20260109231151.4056804-20-sjg@u-boot.org
State New
Headers
Series boot: pxe: Refactor into separate load/setup phases |

Commit Message

Simon Glass Jan. 9, 2026, 11:11 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Return early if no FDT file is specified, rather than using an else
branch. This flattens the code and makes the control flow clearer.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 boot/pxe_utils.c | 54 ++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)
  

Patch

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index f6ad3f905b9..c0ef524f3f1 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -526,39 +526,39 @@  static int label_load_fdt(struct pxe_context *ctx, struct pxe_label *label,
 	if (ret)
 		return ret;
 
-	if (fdtfile) {
-		ret = get_relfile_envaddr(ctx, fdtfile, "fdt_addr_r", SZ_4K,
-					  (enum bootflow_img_t)IH_TYPE_FLATDT,
-					  &addr, NULL);
-
-		free(fdtfile);
-		if (ret < 0) {
-			*fdt_argp = NULL;
-
-			if (label->fdt) {
-				printf("Skipping %s for failure retrieving FDT\n",
-				       label->name);
-				return -ENOENT;
-			}
+	if (!fdtfile) {
+		*fdt_argp = NULL;
+		return 0;
+	}
 
-			if (label->fdtdir) {
-				printf("Skipping fdtdir %s for failure retrieving dts\n",
-				       label->fdtdir);
-			}
-		} else {
-			ctx->fdt = map_sysmem(addr, 0);
+	ret = get_relfile_envaddr(ctx, fdtfile, "fdt_addr_r", SZ_4K,
+				  (enum bootflow_img_t)IH_TYPE_FLATDT,
+				  &addr, NULL);
+	free(fdtfile);
+	if (ret < 0) {
+		*fdt_argp = NULL;
 
-			if (label->kaslrseed)
-				label_boot_kaslrseed(ctx);
+		if (label->fdt) {
+			printf("Skipping %s for failure retrieving FDT\n",
+			       label->name);
+			return -ENOENT;
+		}
 
-			if (IS_ENABLED(CONFIG_OF_LIBFDT_OVERLAY) &&
-			    label->fdtoverlays)
-				label_boot_fdtoverlay(ctx, label);
+		if (label->fdtdir) {
+			printf("Skipping fdtdir %s for failure retrieving dts\n",
+			       label->fdtdir);
 		}
-	} else {
-		*fdt_argp = NULL;
+		return 0;
 	}
 
+	ctx->fdt = map_sysmem(addr, 0);
+
+	if (label->kaslrseed)
+		label_boot_kaslrseed(ctx);
+
+	if (IS_ENABLED(CONFIG_OF_LIBFDT_OVERLAY) && label->fdtoverlays)
+		label_boot_fdtoverlay(ctx, label);
+
 	return 0;
 }
 /**