From ea65d215735661926b50e5442c0571d102f3b0b8 Mon Sep 17 00:00:00 2001 From: Jakub Dabek Date: Fri, 23 Feb 2024 15:59:08 +0100 Subject: [PATCH] vmh: fix allocation size value calculation Allocation sizes were calculated with faulty logic. Bits to check size calculation is not needed since array position was calculated and loop should go from this position to array end. Signed-off-by: Jakub Dabek --- zephyr/lib/regions_mm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/zephyr/lib/regions_mm.c b/zephyr/lib/regions_mm.c index 1a0d4f00b5be..9a232cf03d09 100644 --- a/zephyr/lib/regions_mm.c +++ b/zephyr/lib/regions_mm.c @@ -552,20 +552,14 @@ int vmh_free(struct vmh_heap *heap, void *ptr) return -EINVAL; if (bit_value) { - /* We know we have more than one block was allocated so - * we need to find the size - */ - size_t bits_to_check = - heap->physical_blocks_allocators - [mem_block_iter]->info.num_blocks - ptr_bit_array_position; - /* Neeeeeeeds optimization - thinking how to do it properly * each set bit in order after another means one allocated block. * When we get to 0 in such range we know that is last allocated block. * Testing bundles looks promising - need to investigate. */ for (i = ptr_bit_array_position; - i < bits_to_check; + i < heap->physical_blocks_allocators + [mem_block_iter]->info.num_blocks; i++) { sys_bitarray_test_bit(heap->allocation_sizes[mem_block_iter], i,