From 45b7e12cf96f7162f0cc6cf70c405be88b605619 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Mon, 15 Feb 2021 09:25:14 -0800 Subject: [PATCH] Fix fb_alloc_all cache alignment --- src/omv/alloc/fb_alloc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/omv/alloc/fb_alloc.c b/src/omv/alloc/fb_alloc.c index 3d088e3bf..7059738cd 100644 --- a/src/omv/alloc/fb_alloc.c +++ b/src/omv/alloc/fb_alloc.c @@ -209,13 +209,6 @@ void *fb_alloc_all(uint32_t *size, int hints) *size = (temp / sizeof(uint32_t)) * sizeof(uint32_t); // Round Down - #if __DCACHE_PRESENT - if (hints & FB_ALLOC_CACHE_ALIGN) { - *size = ((*size + __SCB_DCACHE_LINE_SIZE - 1) / __SCB_DCACHE_LINE_SIZE) * __SCB_DCACHE_LINE_SIZE; - *size += __SCB_DCACHE_LINE_SIZE; - } - #endif - char *result = pointer - *size; char *new_pointer = result - sizeof(uint32_t); @@ -244,8 +237,11 @@ void *fb_alloc_all(uint32_t *size, int hints) if (hints & FB_ALLOC_CACHE_ALIGN) { int offset = ((uint32_t) result) % __SCB_DCACHE_LINE_SIZE; if (offset) { - result += __SCB_DCACHE_LINE_SIZE - offset; + int inc = __SCB_DCACHE_LINE_SIZE - offset; + result += inc; + *size -= inc; } + *size = (*size / __SCB_DCACHE_LINE_SIZE) * __SCB_DCACHE_LINE_SIZE; } #endif