[U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign()

Simon Glass sjg at chromium.org
Sat May 19 14:37:11 UTC 2018


Hi Ley,

On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan at intel.com> wrote:
> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use
> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes
> to align with the requested alignment.
>
> The original memalign() function will access mchunkptr struct to adjust the
> alignment if there is misalignment happen, but mchunkptr struct is not being
> initialized before full malloc is initialized. This cause the system crash.
>
> Signed-off-by: Ley Foon Tan <ley.foon.tan at intel.com>
> ---
>  common/dlmalloc.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/common/dlmalloc.c b/common/dlmalloc.c
> index b395eef..edaad29 100644
> --- a/common/dlmalloc.c
> +++ b/common/dlmalloc.c
> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
>
>    if ((long)bytes < 0) return NULL;
>
> +#if CONFIG_VAL(SYS_MALLOC_F_LEN)

How about:

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

?

> +       if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
> +               nb = roundup(bytes, alignment);
> +               return malloc_simple(nb);
> +       }
> +#endif
> +
>    /* If need less alignment than we give anyway, just relay to malloc */
>
>    if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes);
> --
> 1.7.1
>

Regards,
Simon


More information about the U-Boot mailing list