[PATCH v3 3/9] bloblist: refactor of bloblist_reloc()

Ilias Apalodimas ilias.apalodimas at linaro.org
Wed Dec 27 09:32:30 CET 2023


Hi Raymond

On Fri, 22 Dec 2023 at 23:31, Raymond Mao <raymond.mao at linaro.org> wrote:
>
> The current bloblist pointer and size can be retrieved from global
> data, so we don't need to pass them from the function arguments.
> This change also help to remove all external access of gd->bloblist
> outside of bloblist module.
>
> Signed-off-by: Raymond Mao <raymond.mao at linaro.org>
> ---
> Changes in v2
> - New patch file created for v2.
> Changes in v3
> - Check the space size before copying the bloblist.
> - Add return code of bloblist_reloc().
>
>  common/bloblist.c  | 10 ++++++++--
>  common/board_f.c   |  8 ++------
>  include/bloblist.h |  8 ++++----
>  test/bloblist.c    |  6 ++----
>  4 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/common/bloblist.c b/common/bloblist.c
> index db3fbb20cf..5ad1db137a 100644
> --- a/common/bloblist.c
> +++ b/common/bloblist.c
> @@ -472,13 +472,19 @@ void bloblist_show_list(void)
>         }
>  }
>
> -void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
> +int bloblist_reloc(void *to, uint to_size)
>  {
>         struct bloblist_hdr *hdr;
>
> -       memcpy(to, from, from_size);
> +       if (to_size < gd->bloblist->total_size)
> +               return -ENOSPC;
> +
> +       memcpy(to, gd->bloblist, gd->bloblist->total_size);
>         hdr = to;
>         hdr->total_size = to_size;
> +       gd->bloblist = to;
> +
> +       return 0;
>  }
>
>  int bloblist_init(void)
> diff --git a/common/board_f.c b/common/board_f.c
> index d4d7d01f8f..00b0430889 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -676,13 +676,9 @@ static int reloc_bloblist(void)
>                 return 0;
>         }
>         if (gd->new_bloblist) {
> -               int size = CONFIG_BLOBLIST_SIZE;
> -
>                 debug("Copying bloblist from %p to %p, size %x\n",
> -                     gd->bloblist, gd->new_bloblist, size);
> -               bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
> -                              gd->bloblist, size);
> -               gd->bloblist = gd->new_bloblist;
> +                     gd->bloblist, gd->new_bloblist, gd->bloblist->total_size);
> +               bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC);

Why aren't we checking bloblist_reloc() for an error?

>         }
>  #endif
>
[...]

Thanks
/Ilias


More information about the U-Boot mailing list