From: Simon Glass <simon.glass@canonical.com> The parse_pxefile() function uses map_sysmem() to map the file contents. Currently it passes 0 for the size, which works but is not ideal. Add an explicit size parameter so callers can provide the actual file size. Internal callers use ctx->pxe_file_size which is set by get_pxe_file(). Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- boot/pxe_utils.c | 7 ++++--- include/pxe_utils.h | 4 +++- test/boot/pxe.c | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 2d9081e6e9b..6416ee3ddff 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -1004,7 +1004,8 @@ void pxe_menu_uninit(struct pxe_menu *cfg) free(cfg); } -struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg) +struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg, + ulong size) { struct pxe_menu *cfg; char *buf; @@ -1014,7 +1015,7 @@ struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg) if (!cfg) return NULL; - buf = map_sysmem(menucfg, 0); + buf = map_sysmem(menucfg, size); r = parse_pxefile_top(ctx, buf, menucfg, cfg, 1); unmap_sysmem(buf); @@ -1306,7 +1307,7 @@ static struct pxe_menu *pxe_prepare(struct pxe_context *ctx, struct pxe_menu *cfg; int ret; - cfg = parse_pxefile(ctx, pxefile_addr_r); + cfg = parse_pxefile(ctx, pxefile_addr_r, ctx->pxe_file_size); if (!cfg) { printf("Error parsing config file\n"); return NULL; diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 266204b97ef..50e0c0c6b93 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -299,10 +299,12 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg); * * @ctx: PXE context (provided by the caller) * @menucfg: Address of the PXE file in memory + * @size: Size of file in bytes * Return: NULL on error, otherwise a pointer to a pxe_menu struct. Use * pxe_menu_uninit() to free it. */ -struct pxe_menu *parse_pxefile(struct pxe_context *ctx, ulong menucfg); +struct pxe_menu *parse_pxefile(struct pxe_context *ctx, ulong menucfg, + ulong size); /** * pxe_process_includes() - Process include files in a parsed menu diff --git a/test/boot/pxe.c b/test/boot/pxe.c index a1ce27ea2a7..1a990a8e348 100644 --- a/test/boot/pxe.c +++ b/test/boot/pxe.c @@ -161,7 +161,7 @@ static int pxe_test_parse_norun(struct unit_test_state *uts) ut_asserteq(1, ret); /* get_pxe_file returns 1 on success */ /* Parse the config file */ - cfg = parse_pxefile(&ctx, addr); + cfg = parse_pxefile(&ctx, addr, ctx.pxe_file_size); ut_assertnonnull(cfg); /* Process any include files */ @@ -465,7 +465,7 @@ static int pxe_test_fdtdir_norun(struct unit_test_state *uts) /* Read and parse the config file */ ut_asserteq(1, get_pxe_file(&ctx, cfg_path, addr)); - cfg = parse_pxefile(&ctx, addr); + cfg = parse_pxefile(&ctx, addr, ctx.pxe_file_size); ut_assertnonnull(cfg); /* Consume parsing output */ @@ -574,7 +574,7 @@ static int pxe_test_errors_norun(struct unit_test_state *uts) /* Read and parse the config file */ ut_asserteq(1, get_pxe_file(&ctx, cfg_path, addr)); - cfg = parse_pxefile(&ctx, addr); + cfg = parse_pxefile(&ctx, addr, ctx.pxe_file_size); ut_assertnonnull(cfg); /* Consume parsing output */ @@ -693,7 +693,7 @@ static int pxe_test_overlay_no_addr_norun(struct unit_test_state *uts) ctx.quiet = true; ut_asserteq(1, get_pxe_file(&ctx, cfg_path, addr)); - cfg = parse_pxefile(&ctx, addr); + cfg = parse_pxefile(&ctx, addr, ctx.pxe_file_size); ut_assertnonnull(cfg); /* Process any include files */ @@ -1268,7 +1268,7 @@ static int pxe_test_fit_embedded_fdt_norun(struct unit_test_state *uts) /* Read and parse the config file */ ut_asserteq(1, get_pxe_file(&ctx, cfg_path, addr)); - cfg = parse_pxefile(&ctx, addr); + cfg = parse_pxefile(&ctx, addr, ctx.pxe_file_size); ut_assertnonnull(cfg); /* Consume parsing output */ -- 2.43.0