From f217a0b2d6ed672b1f8e4d5a2da2ddc5ba2f5a7b Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 8 Oct 2024 06:40:38 +0200 Subject: [PATCH] Check the region size after address alignment --- lwmem/src/lwmem/lwmem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 969e3bc..34b8513 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -203,6 +203,12 @@ prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms mem_size -= (size_t)(mem_start_addr - LWMEM_TO_BYTE_PTR(region->start_addr)); } + /* Check region size and align it to config bits */ + mem_size = region->size & ~LWMEM_ALIGN_BITS; /* Size does not include lower bits */ + if (mem_size < (2 * LWMEM_BLOCK_MIN_SIZE)) { + return 0; + } + /* Check final memory size */ if (mem_size >= (2 * LWMEM_BLOCK_MIN_SIZE)) { *msa = mem_start_addr;