All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign()
@ 2018-05-18 10:03 Ley Foon Tan
  2018-05-18  8:21 ` Marek Vasut
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Ley Foon Tan @ 2018-05-18 10:03 UTC (permalink / raw)
  To: u-boot

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>
---
 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)
+	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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-05-30 19:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 10:03 [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() Ley Foon Tan
2018-05-18  8:21 ` Marek Vasut
2018-05-19 14:37 ` Simon Glass
2018-05-23  6:32   ` Ley Foon Tan
2018-05-23 16:33     ` Simon Glass
2018-05-25  3:24       ` Ley Foon Tan
2018-05-25  3:33         ` Simon Glass
2018-05-25  8:50           ` Ley Foon Tan
2018-05-26  2:06             ` Simon Glass
2018-05-29  5:16               ` Masahiro Yamada
2018-05-30 19:18                 ` Simon Glass
2018-05-28 19:13 ` [U-Boot] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.