diff mbox series

[U-Boot] malloc: Fix memalign not honoring alignment prior to full malloc init

Message ID 20190327181726.16590-1-dannenberg@ti.com
State Accepted
Commit 4c6be01c2719e78cd7ff257dd65a666623566863
Delegated to: Tom Rini
Headers show
Series [U-Boot] malloc: Fix memalign not honoring alignment prior to full malloc init | expand

Commit Message

Andreas Dannenberg March 27, 2019, 6:17 p.m. UTC
When using memalign() in a scenario where U-Boot is configured for full
malloc support with simple malloc not explicitly enabled and before the
full malloc support is initialized, a memory block is being allocated
and returned without the alignment parameter getting honored.

Fix this issue by replacing the existing memalign pre-full malloc init
logic with a call to memalign_simple() this way ensuring proper alignment
of the returned memory block.

Fixes: ee038c58d519 ("malloc: Use malloc simple before malloc is fully initialized in memalign()")
Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
---
 common/dlmalloc.c | 3 +--
 include/malloc.h  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

Comments

Lokesh Vutla March 28, 2019, 3:25 a.m. UTC | #1
On 27/03/19 11:47 PM, Andreas Dannenberg wrote:
> When using memalign() in a scenario where U-Boot is configured for full
> malloc support with simple malloc not explicitly enabled and before the
> full malloc support is initialized, a memory block is being allocated
> and returned without the alignment parameter getting honored.
> 
> Fix this issue by replacing the existing memalign pre-full malloc init
> logic with a call to memalign_simple() this way ensuring proper alignment
> of the returned memory block.
> 
> Fixes: ee038c58d519 ("malloc: Use malloc simple before malloc is fully initialized in memalign()")
> Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
> ---

Good catch.

Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>

Thanks and regards,
Lokesh
Andreas Dannenberg April 16, 2019, 4:48 p.m. UTC | #2
Hi Tom et al.,

On Wed, Mar 27, 2019 at 01:17:26PM -0500, Andreas Dannenberg wrote:
> When using memalign() in a scenario where U-Boot is configured for full
> malloc support with simple malloc not explicitly enabled and before the
> full malloc support is initialized, a memory block is being allocated
> and returned without the alignment parameter getting honored.
> 
> Fix this issue by replacing the existing memalign pre-full malloc init
> logic with a call to memalign_simple() this way ensuring proper alignment
> of the returned memory block.
> 
> Fixes: ee038c58d519 ("malloc: Use malloc simple before malloc is fully initialized in memalign()")
> Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>

Any additonal feedback/comments on this patch?

Thanks, Andreas

> ---
>  common/dlmalloc.c | 3 +--
>  include/malloc.h  | 2 +-
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/common/dlmalloc.c b/common/dlmalloc.c
> index edaad299bb..6f12a18d54 100644
> --- a/common/dlmalloc.c
> +++ b/common/dlmalloc.c
> @@ -1893,8 +1893,7 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
>  
>  #if CONFIG_VAL(SYS_MALLOC_F_LEN)
>  	if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
> -		nb = roundup(bytes, alignment);
> -		return malloc_simple(nb);
> +		return memalign_simple(alignment, bytes);
>  	}
>  #endif
>  
> diff --git a/include/malloc.h b/include/malloc.h
> index b714fedf45..5efa6920b2 100644
> --- a/include/malloc.h
> +++ b/include/malloc.h
> @@ -878,7 +878,6 @@ extern Void_t*     sbrk();
>  #define memalign memalign_simple
>  static inline void free(void *ptr) {}
>  void *calloc(size_t nmemb, size_t size);
> -void *memalign_simple(size_t alignment, size_t bytes);
>  void *realloc_simple(void *ptr, size_t size);
>  void malloc_simple_info(void);
>  #else
> @@ -914,6 +913,7 @@ int initf_malloc(void);
>  
>  /* Simple versions which can be used when space is tight */
>  void *malloc_simple(size_t size);
> +void *memalign_simple(size_t alignment, size_t bytes);
>  
>  #pragma GCC visibility push(hidden)
>  # if __STD_C
> -- 
> 2.17.1
>
Tom Rini April 24, 2019, 1:30 p.m. UTC | #3
On Wed, Mar 27, 2019 at 01:17:26PM -0500, Andreas Dannenberg wrote:

> When using memalign() in a scenario where U-Boot is configured for full
> malloc support with simple malloc not explicitly enabled and before the
> full malloc support is initialized, a memory block is being allocated
> and returned without the alignment parameter getting honored.
> 
> Fix this issue by replacing the existing memalign pre-full malloc init
> logic with a call to memalign_simple() this way ensuring proper alignment
> of the returned memory block.
> 
> Fixes: ee038c58d519 ("malloc: Use malloc simple before malloc is fully initialized in memalign()")
> Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
> Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index edaad299bb..6f12a18d54 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1893,8 +1893,7 @@  Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
 	if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
-		nb = roundup(bytes, alignment);
-		return malloc_simple(nb);
+		return memalign_simple(alignment, bytes);
 	}
 #endif
 
diff --git a/include/malloc.h b/include/malloc.h
index b714fedf45..5efa6920b2 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -878,7 +878,6 @@  extern Void_t*     sbrk();
 #define memalign memalign_simple
 static inline void free(void *ptr) {}
 void *calloc(size_t nmemb, size_t size);
-void *memalign_simple(size_t alignment, size_t bytes);
 void *realloc_simple(void *ptr, size_t size);
 void malloc_simple_info(void);
 #else
@@ -914,6 +913,7 @@  int initf_malloc(void);
 
 /* Simple versions which can be used when space is tight */
 void *malloc_simple(size_t size);
+void *memalign_simple(size_t alignment, size_t bytes);
 
 #pragma GCC visibility push(hidden)
 # if __STD_C