[PATCH 4/5] tlsf_malloc: Set errno to ENOMEM on failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Set errno to ENOMEM on failure so that correct error message can be
displayed by users who rely on errno.

Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
---
 common/tlsf_malloc.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index aa3ab2397..c8900fc6b 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -28,6 +28,7 @@ extern tlsf_pool tlsf_mem_pool;
 
 void *malloc(size_t bytes)
 {
+	void *mem;
 	/*
 	 * tlsf_malloc returns NULL for zero bytes, we instead want
 	 * to have a valid pointer.
@@ -35,7 +36,11 @@ void *malloc(size_t bytes)
 	if (!bytes)
 		bytes = 1;
 
-	return tlsf_malloc(tlsf_mem_pool, bytes);
+	mem = tlsf_malloc(tlsf_mem_pool, bytes);
+	if (!mem)
+		errno = ENOMEM;
+
+	return mem;
 }
 EXPORT_SYMBOL(malloc);
 
@@ -47,13 +52,21 @@ EXPORT_SYMBOL(free);
 
 void *realloc(void *oldmem, size_t bytes)
 {
-	return tlsf_realloc(tlsf_mem_pool, oldmem, bytes);
+	void *mem = tlsf_realloc(tlsf_mem_pool, oldmem, bytes);
+	if (!mem)
+		errno = ENOMEM;
+
+	return mem;
 }
 EXPORT_SYMBOL(realloc);
 
 void *memalign(size_t alignment, size_t bytes)
 {
-	return tlsf_memalign(tlsf_mem_pool, alignment, bytes);
+	void *mem = tlsf_memalign(tlsf_mem_pool, alignment, bytes);
+	if (!mem)
+		errno = ENOMEM;
+
+	return mem;
 }
 EXPORT_SYMBOL(memalign);
 
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux