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

Evgeny Bachinin eabachinin at salutedevices.com
Tue Dec 17 09:59:29 CET 2024


Hi, Simon, see below

On Fri, Dec 06, 2024 at 08:31:36AM -0700, Simon Glass wrote:
> Hi Evgeny,
> 
> On Mon, 2 Dec 2024 at 06:46, Evgeny Bachinin
> <EABachinin at salutedevices.com> wrote:
> >
> > 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
> >
>
> Reviewed-by: Simon Glass <sjg at chromium.org>
>
> But note for the future we have:
>
> https://patchwork.ozlabs.org/project/uboot/patch/20241102174944.412088-2-sjg@chromium.org/

Thanks for pointing me!

Could you advise me?
Should I abandon this patch from v2 patch-set?

--
Best Regards,
Evgeny Bachinin


More information about the U-Boot mailing list