[PATCH 5/5] sandbox: set retval early in board_fdt_blob_setup()

Evgeny Bachinin EABachinin at salutedevices.com
Mon Dec 2 14:45:26 CET 2024


Bug:
nobody sets 'ret' to non-error value inside board_fdt_blob_setup()
in case, when gd->fdt_blob has been initialized before calling the
board_fdt_blob_setup() (say, due to CONFIG_OF_EMBED=y)

Reproduced with CONFIG_OF_EMBED=y && BLOBLIST=n.
  ```
    $ ./u-boot
    initcall: 0000000000078e05 (relocated to 000061138d2c7e05)
    initcall: 0000000000117b12 (relocated to 000061138d366b12)
      fdtdec_setup():
            gd->fdt_blob = dtb_dt_embedded()
      fdtdec_setup():
            gd->fdt_blob = board_fdt_blob_setup(&ret);

        board_fdt_blob_setup():380 ret:-2 gd->fdt_blob:0x61138d4db310
                if (gd->fdt_blob)
                        return (void *)gd->fdt_blob;

    initcall failed at call 0000000000117b12 (err=-2: No such file \
       or directory)
    ### ERROR ### Please RESET the board ###
  ```

Patch moves code, zeroizing the 'ret', before checking the fdt_blob.

Fixes: d8289e7dfe5 ("sandbox: fdt: Avoid overwriting an existing fdt")
Signed-off-by: Evgeny Bachinin <EABachinin at salutedevices.com>
---
 arch/sandbox/cpu/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index d1c4dcf0764fb37ec99585a3db16fa34c3a54dac..7e93377e87e75b0fb92a8cf139b4a731a88a6a7b 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -377,10 +377,10 @@ void *board_fdt_blob_setup(int *ret)
 	int err;
 	int fd;
 
+	*ret = 0;
 	if (gd->fdt_blob)
 		return (void *)gd->fdt_blob;
 	blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
-	*ret = 0;
 	if (!state->fdt_fname) {
 		err = setup_auto_tree(blob);
 		if (!err)

-- 
2.34.1



More information about the U-Boot mailing list