Skip to contentSkip to conversation

malloc_simple: fix malloc_ptr calculation

PATCH In review Philipp Rosenberger 4 participants 4 messages Sep 8, 2015 – Sep 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 malloc_simple: fix malloc_ptr calculation

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.

---
 common/malloc_simple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/malloc_simple.c +1 -1
index 134e059..c745863 100644
@@ -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);
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 malloc_simple: fix malloc_ptr calculation

Hi,

Quoted 5 lines · Philipp Rosenberger

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.

You're right, good catch:

Regards,

Hans

Quoted 18 lines
---
  common/malloc_simple.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
common/malloc_simple.c +1 -1
index 134e059..c745863 100644
@@ -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 lore raw
In reply to Philipp Rosenberger
Quoted 6 lines · Philipp Rosenberger

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.

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150928/98dd2f33/attachment.sig>
#3 lore raw
Quoted 7 lines · Tom Rini
Quoted 5 lines · Philipp Rosenberger

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.

Just bisected down git master not booting on my RK3288 board anymore, turned out to be this patch. Reverting it on master makes for a much happier board...

I'll dig a bit deeper what's going on here now.

Signature · 2 lines
Sjoerd Simons
Collabora Ltd.