From 3209a97c5c391aee3bbd3aab25853d9c4a5daff9 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Thu, 17 Oct 2024 12:40:33 +0200 Subject: [PATCH] util/vma: Fix util_vma_heap_get_max_free_continuous_size calculation It was based on misunderstanding of how holes are sorted, they are sorted by address and not by size. Fixes: df3ba95a2498447b037d0d8efbdf605be25ff8ff ("util/vma: Add function to get max continuous free size") Signed-off-by: Danylo Piliaiev Part-of: --- src/util/vma.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/util/vma.c b/src/util/vma.c index a91bd471f7d..3ca1be9d72e 100644 --- a/src/util/vma.c +++ b/src/util/vma.c @@ -355,11 +355,12 @@ util_vma_heap_free(struct util_vma_heap *heap, uint64_t util_vma_heap_get_max_free_continuous_size(struct util_vma_heap *heap) { - if (list_is_empty(&heap->holes)) - return 0; + uint64_t max_size = 0; + util_vma_foreach_hole_safe(hole, heap) { + max_size = MAX2(max_size, hole->size); + } - struct util_vma_hole *top_hole = list_first_entry(&heap->holes, struct util_vma_hole, link); - return top_hole->size; + return max_size; } void