All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ley Foon Tan <ley.foon.tan@intel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign()
Date: Fri, 18 May 2018 18:03:12 +0800	[thread overview]
Message-ID: <1526637792-33233-1-git-send-email-ley.foon.tan@intel.com> (raw)

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

             reply	other threads:[~2018-05-18 10:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 10:03 Ley Foon Tan [this message]
2018-05-18  8:21 ` [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1526637792-33233-1-git-send-email-ley.foon.tan@intel.com \
    --to=ley.foon.tan@intel.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.