diff mbox

[U-Boot,2/7] malloc_simple: Fix malloc_ptr calculation

Message ID 1442158965-29962-3-git-send-email-hdegoede@redhat.com
State Accepted
Delegated to: Hans de Goede
Headers show

Commit Message

Hans de Goede Sept. 13, 2015, 3:42 p.m. UTC
From: Philipp Rosenberger <ilu@linutronix.de>

The gd->malloc_ptr and the gd->malloc_limit are offsets to gd->malloc_base.
But the addr variable contains the absolute address. The new_ptr must be:
addr + bytes - gd->malloc_base.

Signed-off-by: Philipp Rosenberger <ilu@linutronix.de>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 common/malloc_simple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass Sept. 22, 2015, 4 a.m. UTC | #1
On 13 September 2015 at 09:42, Hans de Goede <hdegoede@redhat.com> wrote:
> From: Philipp Rosenberger <ilu@linutronix.de>
>
> The gd->malloc_ptr and the gd->malloc_limit are offsets to gd->malloc_base.
> But the addr variable contains the absolute address. The new_ptr must be:
> addr + bytes - gd->malloc_base.
>
> Signed-off-by: Philipp Rosenberger <ilu@linutronix.de>
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  common/malloc_simple.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Eek! Nice to find this one.

Reviewed-by: Simon Glass <sjg@chromium.org>

>
> diff --git a/common/malloc_simple.c b/common/malloc_simple.c
> index 134e059..c745863 100644
> --- a/common/malloc_simple.c
> +++ b/common/malloc_simple.c
> @@ -32,7 +32,7 @@ void *memalign_simple(size_t align, size_t bytes)
>         void *ptr;
>
>         addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align);
> -       new_ptr = addr + bytes;
> +       new_ptr = addr + bytes - gd->malloc_base;
>         if (new_ptr > gd->malloc_limit)
>                 return NULL;
>         ptr = map_sysmem(addr, bytes);
> --
> 2.4.3
>
diff mbox

Patch

diff --git a/common/malloc_simple.c b/common/malloc_simple.c
index 134e059..c745863 100644
--- a/common/malloc_simple.c
+++ b/common/malloc_simple.c
@@ -32,7 +32,7 @@  void *memalign_simple(size_t align, size_t bytes)
 	void *ptr;
 
 	addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align);
-	new_ptr = addr + bytes;
+	new_ptr = addr + bytes - gd->malloc_base;
 	if (new_ptr > gd->malloc_limit)
 		return NULL;
 	ptr = map_sysmem(addr, bytes);