[PATCH 1/1] tools/fdt_add_pubkey: error handling in add_pubkey

Simon Glass sjg at chromium.org
Mon Jul 31 19:08:00 CEST 2023


Hi,

On Mon, 31 Jul 2023 at 02:16, Ivan Mikhaylov <fr0st61te at gmail.com> wrote:
>
> On Sun, 2023-07-30 at 10:15 +0200, Heinrich Schuchardt wrote:
> > * If info is NULL, do not dereference it.
> > * If mmap fails, print an error message.
> >
> > Fixes: 30238e99619c ("tools: add fdt_add_pubkey")
> > Signed-off-by: Heinrich Schuchardt
> > <heinrich.schuchardt at canonical.com>
> > ---
> >  tools/fdt_add_pubkey.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/fdt_add_pubkey.c b/tools/fdt_add_pubkey.c
> > index 5582d7a8ef..7843a006f0 100644
> > --- a/tools/fdt_add_pubkey.c
> > +++ b/tools/fdt_add_pubkey.c
> > @@ -89,8 +89,10 @@ static int add_pubkey(struct image_sign_info
> > *info)
> >         struct stat dest_sbuf;
> >         size_t size_inc = 0;
> >
> > -       if (!info)
> > +       if (!info) {
> >                 fprintf(stderr, "Error: info is NULL in %s\n",
> > __func__);
> > +               return -EINVAL;
> > +       }
> >
> >         do {
> >                 if (destfd >= 0) {
> > @@ -104,7 +106,7 @@ static int add_pubkey(struct image_sign_info
> > *info)
> >                 destfd = mmap_fdt(cmdname, keydest, size_inc,
> > &dest_blob,
> >                                   &dest_sbuf, false, false);
> >                 if (destfd < 0)
> > -                       exit(EXIT_FAILURE);
> > +                       return -ENOSPC;
>
> Heinrich, mmap_fdt may return a lot of errors, not just ENOSPC. I don't
> think that is correct.

We could use perror() to print it here?

I suppose -ENOSPC is used to make it try again, but why will it
succeed in that case? IOW why is this error not fatal?

>
> Thanks.
>
> >
> >                 ret = info->crypto->add_verify_data(info, dest_blob);
> >                 if (ret == -ENOSPC)

Regards,
Simon


More information about the U-Boot mailing list