From 0ec10f93a563fb6635f121ef9ec2ae0ea675c63a Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Fri, 4 Jan 2019 10:53:20 +0100 Subject: fwk: mm: Trap allocation errors in debug mode Change-Id: I3b8f6349e3fbd1db05f8aefca6434f1ccbdad800 Signed-off-by: Ronald Cron --- framework/src/fwk_mm.c | 15 ++++++++++----- 1 file 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 #include #include +#include #include #include #include @@ -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) -- cgit v1.2.3