Hi Randolph, On 2026-05-13T20:49:42, Randolph Sapp <[email protected]> wrote: > test: boot: add a fdt reserved region check > > Add a image_fdt suite and a check for boot_fdt_add_mem_rsv_regions. This > will ensure the user is properly informed of any reservation failures. > It will also validate that reservations are cleaned up correctly when > switching FDTs. > > Signed-off-by: Randolph Sapp <[email protected]> > Acked-by: Ilias Apalodimas <[email protected]> > > test/boot/Makefile | 1 + > test/boot/image_fdt.c | 70 > +++++++++++++++++++++++++++++++++++++++++++++ > test/cmd_ut.c | 2 ++ > test/py/tests/test_suite.py | 2 +- > 4 files changed, 74 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass <[email protected]> > diff --git a/test/boot/image_fdt.c b/test/boot/image_fdt.c > @@ -0,0 +1,70 @@ > + fdt_sz = fdt_totalsize(gd->fdt_blob); > + new_blob = malloc(fdt_sz); > + ut_assertok_ptr(new_blob); > + memcpy(new_blob, gd->fdt_blob, fdt_sz); ut_assertok_ptr() only checks IS_ERR(), but malloc() returns NULL on failure. IS_ERR(NULL) is false, so a failed allocation sails through and crashes in the memcpy() below. Please use ut_assertnonnull(new_blob) here. > diff --git a/test/boot/image_fdt.c b/test/boot/image_fdt.c > @@ -0,0 +1,70 @@ > + boot_fdt_add_mem_rsv_regions(new_blob); > + gd->fdt_blob = new_blob; > + > + if (ut_assert_console_end()) > + goto switch_fdt; This doesn't do what it looks like. ut_assert_console_end() expands to a block that does 'return CMD_RET_FAILURE' on failure, so the if condition is always 0 and the goto is dead code. If the assertion fails, the function returns immediately, leaving gd->fdt_blob pointing at new_blob and leaking it. To defer cleanup, either restructure so gd->fdt_blob isn't changed until after the check, or use ut_check_console_end() and handle the result yourself. The same applies to the ut_assertok_ptr()/ut_assertnonnull() above - once gd->fdt_blob is mutated, any macro that early-returns skips the cleanup labels. We have a similar problem in the bootstd tests... Regards, Simon

