[U-Boot] [PATCH 09/10] malloc_simple: Display an error when memory is exhausted

Simon Glass sjg at chromium.org
Tue Dec 29 13:22:51 CET 2015


This is an uncommon but annoying case. Normal error handling will ensure it
is reported, but it is useful to have a message which provides a little more
detail.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 common/malloc_simple.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/malloc_simple.c b/common/malloc_simple.c
index 479a1e4..4621b6d 100644
--- a/common/malloc_simple.c
+++ b/common/malloc_simple.c
@@ -21,8 +21,11 @@ void *malloc_simple(size_t bytes)
 	new_ptr = gd->malloc_ptr + bytes;
 	debug("%s: size=%zx, ptr=%lx, limit=%lx\n", __func__, bytes, new_ptr,
 	      gd->malloc_limit);
-	if (new_ptr > gd->malloc_limit)
+	if (new_ptr > gd->malloc_limit) {
+		printf("Out of memory (%zu bytes, %lx requested)\n", bytes,
+		       new_ptr);
 		return NULL;
+	}
 	ptr = map_sysmem(gd->malloc_base + gd->malloc_ptr, bytes);
 	gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
 
-- 
2.6.0.rc2.230.g3dd15c0



More information about the U-Boot mailing list