Skip to contentSkip to conversation

malloc: Use malloc simple before malloc is fully initialized in memalign()

PATCH In review Ley Foon Tan 6 participants 12 messages May 18, 2018 – May 30, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +7 -0
index b395eef..edaad29 100644
@@ -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);
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

Quoted 9 lines · Ley Foon Tan

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.

Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

In reply to Ley Foon Tan

Hi Ley,

Quoted 18 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 4 lines
common/dlmalloc.c +1 -0
@@ -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))

?

Quoted 10 lines
common/dlmalloc.c +6 -1
+       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);
--
Quoted 2 lines

1.7.1

Regards,
Simon

#3 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

Quoted 22 lines · Simon Glass

Hi Ley,

Quoted 19 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644
@@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
Quoted 7 lines

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 3 lines
common/dlmalloc.c +1 -0
   if ((long)bytes < 0) return NULL;
 
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)

How about:

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

Quoted 11 lines

?

Quoted 8 lines
common/dlmalloc.c +6 -0
+       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 */
 
Quoted 7 lines
Quoted 4 lines
common/dlmalloc.c +0 -1
   if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes);
--

1.7.1

Regards,
Simon

Regards
Ley Foon

#4 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

Hi,

Quoted 29 lines · Ley Foon Tan
Quoted 28 lines · Simon Glass

Hi Ley,

Quoted 18 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 4 lines
common/dlmalloc.c +1 -0
@@ -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:

Quoted 8 lines
Quoted 1 line

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

So how about

if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)

Or you could use #if if you need to

To me it seems better to use the setting itself (i.e. whether the pre-reloc malloc() is enabled) rather than one of its parameters (the size of the region).

Quoted 13 lines
Quoted 13 lines

?

Quoted 8 lines
common/dlmalloc.c +6 -0
+       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 */
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
common/dlmalloc.c +0 -1
   if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes);
--

1.7.1

Regards,
Simon

#5 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

Quoted 39 lines · Simon Glass

Hi,

Quoted 36 lines · Ley Foon Tan
Quoted 22 lines · Simon Glass

Hi Ley,

Quoted 19 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644
@@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
Quoted 7 lines

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 3 lines
common/dlmalloc.c +1 -0
   if ((long)bytes < 0) return NULL;
 
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)

How about:

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

Quoted 7 lines
Quoted 1 line

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

So how about

if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)

Or you could use #if if you need to

Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working.

It will not go into this code.

Quoted 18 lines

To me it seems better to use the setting itself (i.e. whether the pre-reloc malloc() is enabled) rather than one of its parameters (the size of the region).

Quoted 13 lines
Quoted 13 lines

?

Quoted 8 lines
common/dlmalloc.c +6 -0
+       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 */
 
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
common/dlmalloc.c +0 -1
   if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes);
--

1.7.1

Regards,
Simon

Regards
Ley Foon

#6 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

Hi,

Quoted 43 lines · Ley Foon Tan
Quoted 41 lines · Simon Glass

Hi,

Quoted 37 lines · Ley Foon Tan
Quoted 22 lines · Simon Glass

Hi Ley,

Quoted 19 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644
@@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
Quoted 7 lines

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 3 lines
common/dlmalloc.c +1 -0
   if ((long)bytes < 0) return NULL;
 
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)

How about:

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

Quoted 8 lines
Quoted 5 lines

So how about

if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)

Or you could use #if if you need to

Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working.

Sorry I mean

CONFIG_IS_ENABLED(SYS_MALLOC_F)

That tells you whether the feature is enabled in U-Boot or SPL.

Quoted 8 lines

It will not go into this code.

Quoted 4 lines

To me it seems better to use the setting itself (i.e. whether the pre-reloc malloc() is enabled) rather than one of its parameters (the size of the region).

[..]

Regards,
Simon

#7 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

Quoted 52 lines · Simon Glass

Hi,

Quoted 49 lines · Ley Foon Tan
Quoted 46 lines · Simon Glass

Hi,

Quoted 29 lines · Ley Foon Tan
Quoted 28 lines · Simon Glass

Hi Ley,

Quoted 18 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 4 lines
common/dlmalloc.c +1 -0
@@ -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:

Quoted 8 lines
Quoted 1 line

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

So how about

if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)

Or you could use #if if you need to

Quoted 8 lines
Quoted 2 lines

Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working.

Sorry I mean

CONFIG_IS_ENABLED(SYS_MALLOC_F)

That tells you whether the feature is enabled in U-Boot or SPL.

#if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is with "1".
Need to use #ifdef CONFIG_SYS_MALLOC_F. Do you want to change to this?

Regards
Ley Foon

#8 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

+Masahiro

Quoted 59 lines · Ley Foon Tan
Quoted 57 lines · Simon Glass

Hi,

Quoted 43 lines · Ley Foon Tan
Quoted 41 lines · Simon Glass

Hi,

Quoted 37 lines · Ley Foon Tan
Quoted 22 lines · Simon Glass

Hi Ley,

Quoted 19 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644
@@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
Quoted 7 lines

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 3 lines
common/dlmalloc.c +1 -0
   if ((long)bytes < 0) return NULL;
 
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)

How about:

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

Quoted 8 lines
Quoted 5 lines

So how about

if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)

Or you could use #if if you need to

Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working.

Sorry I mean

Quoted 7 lines
Quoted 3 lines

CONFIG_IS_ENABLED(SYS_MALLOC_F)

That tells you whether the feature is enabled in U-Boot or SPL.

#if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is with "1".

That seems very strange, since it defeats the purpose of the macro.

Masahiro, do you know what going on here?

Quoted 1 line

Need to use #ifdef CONFIG_SYS_MALLOC_F. Do you want to change to this?

Regards,
Simon

#9 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

2018-05-26 11:06 GMT+09:00 Simon Glass <[email protected]>:

Quoted 66 lines

+Masahiro

Quoted 63 lines · Ley Foon Tan
Quoted 60 lines · Simon Glass

Hi,

Quoted 43 lines · Ley Foon Tan
Quoted 41 lines · Simon Glass

Hi,

Quoted 37 lines · Ley Foon Tan
Quoted 22 lines · Simon Glass

Hi Ley,

Quoted 19 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644
@@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
Quoted 7 lines

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 3 lines
common/dlmalloc.c +1 -0
   if ((long)bytes < 0) return NULL;
 
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)

How about:

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

Quoted 8 lines
Quoted 5 lines

So how about

if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)

Or you could use #if if you need to

Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working.

Sorry I mean

CONFIG_IS_ENABLED(SYS_MALLOC_F)

That tells you whether the feature is enabled in U-Boot or SPL.

Quoted 7 lines
Quoted 3 lines

#if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is with "1".

That seems very strange, since it defeats the purpose of the macro.

Masahiro, do you know what going on here?

CONFIG_IS_ENABLED(SYS_MALLOC_F) evaluates
SYS_MALLOC_F, or SPL_SYS_MALLOC_F
depending on which image is being built.

I see SPL_SYS_MALLOC_F_LEN in Kconfig,
but do not see SPL_SYS_MALLOC_F at all.

Signature · 2 lines
Best Regards
Masahiro Yamada
#10 lore raw

PATCH 1/1 malloc: Use malloc simple before malloc is fully initialized in memalign()

Hi Masahiro,

Quoted 76 lines · Masahiro Yamada

2018-05-26 11:06 GMT+09:00 Simon Glass <[email protected]>:

Quoted 66 lines

+Masahiro

Quoted 63 lines · Ley Foon Tan
Quoted 60 lines · Simon Glass

Hi,

Quoted 43 lines · Ley Foon Tan
Quoted 41 lines · Simon Glass

Hi,

Quoted 37 lines · Ley Foon Tan
Quoted 22 lines · Simon Glass

Hi Ley,

Quoted 19 lines · Ley Foon Tan

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.

---
 common/dlmalloc.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/dlmalloc.c +0 -0
index b395eef..edaad29 100644
@@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
Quoted 7 lines

common/dlmalloc.c Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; · line 1894

Quoted 3 lines
common/dlmalloc.c +1 -0
   if ((long)bytes < 0) return NULL;
 
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)

How about:

if (IS_ENABLED(CONFIG_SYS_MALLOC_F))

I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc().

"spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN"

http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762

Quoted 8 lines
Quoted 5 lines

So how about

if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)

Or you could use #if if you need to

Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working.

Sorry I mean

CONFIG_IS_ENABLED(SYS_MALLOC_F)

That tells you whether the feature is enabled in U-Boot or SPL.

Quoted 7 lines
Quoted 3 lines

#if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is with "1".

That seems very strange, since it defeats the purpose of the macro.

Masahiro, do you know what going on here?

Quoted 7 lines

CONFIG_IS_ENABLED(SYS_MALLOC_F) evaluates
SYS_MALLOC_F, or SPL_SYS_MALLOC_F
depending on which image is being built.

I see SPL_SYS_MALLOC_F_LEN in Kconfig,
but do not see SPL_SYS_MALLOC_F at all.

OK, well that explains the problem, thanks.

Regards,
Simon

#11 lore raw
In reply to Ley Foon Tan
Quoted 10 lines · Ley Foon Tan

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.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180528/46a061ea/attachment.sig>