diff options
author | Ronald Cron <ronald.cron@arm.com> | 2019-01-04 10:53:20 +0100 |
---|---|---|
committer | ronald-cron-arm <39518861+ronald-cron-arm@users.noreply.github.com> | 2019-01-08 18:03:40 +0000 |
commit | 0ec10f93a563fb6635f121ef9ec2ae0ea675c63a (patch) | |
tree | eedfe745c85dcd78bd19ba332670d3a0a804fec5 | |
parent | 023d8ef086a83096428ec9497085350709916c00 (diff) |
fwk: mm: Trap allocation errors in debug mode
Change-Id: I3b8f6349e3fbd1db05f8aefca6434f1ccbdad800
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
-rw-r--r-- | framework/src/fwk_mm.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/framework/src/fwk_mm.c b/framework/src/fwk_mm.c index e2b5b687..cc4bb8ba 100644 --- a/framework/src/fwk_mm.c +++ b/framework/src/fwk_mm.c @@ -15,6 +15,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <fwk_assert.h> #include <fwk_errno.h> #include <fwk_macros.h> #include <fwk_mm.h> @@ -67,31 +68,35 @@ void *fwk_mm_alloc_aligned(size_t num, size_t size, unsigned int alignment) bool overflow; if (mm_locked || !num || !size || !alignment || !initialized) - return NULL; + goto error; /* Ensure 'alignment' is a power of two */ if (alignment & (alignment - 1)) - return NULL; + goto error; overflow = __builtin_mul_overflow(num, size, &total_size); /* Ensure the computation of 'total_size' has not overflowed */ if (overflow) - return NULL; + goto error; start = FWK_ALIGN_NEXT(heap_free, alignment); /* Ensure there is no overflow during the alignment */ if (start < heap_free) - return NULL; + goto error; /* Ensure 'total_size' fits in the remaining heap area */ if (total_size > (heap_end - start)) - return NULL; + goto error; heap_free = start + total_size; return (void *)start; + +error: + fwk_expect(false); + return NULL; } void *fwk_mm_calloc(size_t num, size_t size) |