summaryrefslogtreecommitdiffstats
path: root/common/tlsf_malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/tlsf_malloc.c')
-rw-r--r--common/tlsf_malloc.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index a3541d8256..c8900fc6bb 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,25 +36,13 @@ void *malloc(size_t bytes)
if (!bytes)
bytes = 1;
- return tlsf_malloc(tlsf_mem_pool, bytes);
-}
-EXPORT_SYMBOL(malloc);
-
-/*
- * calloc calls malloc, then zeroes out the allocated chunk.
- */
-void *calloc(size_t n, size_t elem_size)
-{
- void *mem;
- size_t sz;
-
- sz = n * elem_size;
- mem = malloc(sz);
- memset(mem, 0, sz);
+ mem = tlsf_malloc(tlsf_mem_pool, bytes);
+ if (!mem)
+ errno = ENOMEM;
return mem;
}
-EXPORT_SYMBOL(calloc);
+EXPORT_SYMBOL(malloc);
void free(void *mem)
{
@@ -63,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);