From de408a23491f48f0ee67d754f792e0b623bf94e8 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 18 Oct 2021 15:17:41 +0300 Subject: [PATCH] zephyr: trigger system panic if MEM_ZONE_SYS alloc fails As per documentation in include/sof/lib/alloc.h, rmalloc from MEM_ZONE_SYS will always succeed. In the unlikely case the alloc fails, trigger a system panic in rmalloc(). Signed-off-by: Kai Vehmanen --- zephyr/wrapper.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/zephyr/wrapper.c b/zephyr/wrapper.c index e14b6e1ad..0932c010a 100644 --- a/zephyr/wrapper.c +++ b/zephyr/wrapper.c @@ -188,14 +188,22 @@ static inline bool zone_is_cached(enum mem_zone zone) void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) { - if (zone_is_cached(zone)) - return heap_alloc_aligned_cached(&sof_heap, 0, bytes); + void *ptr; - /* - * XTOS alloc implementation has used dcache alignment, - * so SOF application code is expecting this behaviour. - */ - return heap_alloc_aligned(&sof_heap, PLATFORM_DCACHE_ALIGN, bytes); + if (zone_is_cached(zone)) { + ptr = heap_alloc_aligned_cached(&sof_heap, 0, bytes); + } else { + /* + * XTOS alloc implementation has used dcache alignment, + * so SOF application code is expecting this behaviour. + */ + ptr = heap_alloc_aligned(&sof_heap, PLATFORM_DCACHE_ALIGN, bytes); + } + + if (!ptr && zone == SOF_MEM_ZONE_SYS) + k_panic(); + + return ptr; } /* Use SOF_MEM_ZONE_BUFFER at the moment */