From f23827a203c5a71a142d3b34f534a4efc82f6f58 Mon Sep 17 00:00:00 2001 From: Jakub Dabek Date: Fri, 9 Feb 2024 16:32:09 +0100 Subject: [PATCH] vmh: fix allocation size check When using non contiguous allocation block size is calculated after the check. Signed-off-by: Jakub Dabek --- zephyr/lib/regions_mm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zephyr/lib/regions_mm.c b/zephyr/lib/regions_mm.c index dbb1aa087..2ee151ac9 100644 --- a/zephyr/lib/regions_mm.c +++ b/zephyr/lib/regions_mm.c @@ -263,9 +263,6 @@ void *vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size) if (!heap->physical_blocks_allocators[mem_block_iterator]) continue; - /* If we do not span alloc and block is smaller than alloc we try next mem_block */ - if (block_size < alloc_size && !heap->allocating_continuously) - continue; /* calculate block count needed to allocate for current * mem_block. */ @@ -273,6 +270,10 @@ void *vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size) 1 << heap->physical_blocks_allocators[mem_block_iterator]->info.blk_sz_shift; block_count = SOF_DIV_ROUND_UP((uint64_t)alloc_size, (uint64_t)block_size); + /* If we do not span alloc and block is smaller than alloc we try next mem_block */ + if (block_size < alloc_size && !heap->allocating_continuously) + continue; + if (block_count > heap->physical_blocks_allocators[mem_block_iterator]->info.num_blocks) continue;