[Concept,15/26] boot: pxe: Set pxe_file_size in get_pxe_file()

Message ID 20260110202906.187370-16-sjg@u-boot.org
State New
Headers
Series boot: pxe: Add three-phase API and fix memory leaks |

Commit Message

Simon Glass Jan. 10, 2026, 8:28 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Currently pxe_file_size is only set by the cmd/pxe.c callback, so other
callers of get_pxe_file() (like tests) do not have access to the file
size.

Add an assignment into get_pxe_file() so the size is always available
in the context after loading a PXE config file.

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

 boot/pxe_utils.c | 1 +
 test/boot/pxe.c  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index a2a2b986de1..2d9081e6e9b 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -151,6 +151,7 @@  int get_pxe_file(struct pxe_context *ctx, const char *file_path,
 	buf = map_sysmem(file_addr + size, 1);
 	*buf = '\0';
 	unmap_sysmem(buf);
+	ctx->pxe_file_size = size;
 
 	return 1;
 }
diff --git a/test/boot/pxe.c b/test/boot/pxe.c
index 2d690141349..a1ce27ea2a7 100644
--- a/test/boot/pxe.c
+++ b/test/boot/pxe.c
@@ -1178,7 +1178,7 @@  static int pxe_test_alloc_norun(struct unit_test_state *uts)
 	ut_asserteq_ptr(&info, ctx.userdata);
 	ut_asserteq(true, ctx.allow_abs_path);
 	ut_assertnonnull(ctx.bootdir);
-	ut_asserteq(0, ctx.pxe_file_size);  /* only set by cmd/pxe.c */
+	ut_assert(ctx.pxe_file_size);  /* set by get_pxe_file() */
 	ut_asserteq(false, ctx.use_ipv6);
 	ut_asserteq(false, ctx.use_fallback);
 	ut_asserteq(true, ctx.no_boot);