summaryrefslogtreecommitdiffstats
path: root/common/tlsf_malloc.c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-10-15 10:00:20 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-16 09:04:08 +0200
commite1818e02408d9e412a2092c2419f323d6b8c7413 (patch)
treef2ebefdbddcd235f681d7aaee2f191663d2c67d8 /common/tlsf_malloc.c
parent7bcf295e8db48474f2ad4e37c7cccc3550fc2904 (diff)
downloadbarebox-e1818e02408d9e412a2092c2419f323d6b8c7413.tar.gz
tlsf_malloc: Set errno to ENOMEM on failure
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@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/tlsf_malloc.c')
-rw-r--r--common/tlsf_malloc.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index aa3ab23..c8900fc 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);