malloc: Use malloc simple before malloc is fully initialized in memalign()
authorLey Foon Tan <ley.foon.tan@intel.com>
Fri, 18 May 2018 10:03:12 +0000 (18:03 +0800)
committerTom Rini <trini@konsulko.com>
Sat, 26 May 2018 22:19:19 +0000 (18:19 -0400)
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@intel.com>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
common/dlmalloc.c

index b395eefbf862cdad5808483750f739edcb8213ed..edaad299bbb552ad8b8710584268e8657f8cd0e7 100644 (file)
@@ -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)
+       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);