From c6531d8b78279e02b2996e2cd33041e47f528111 Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Wed, 1 May 2019 17:22:48 -0400 Subject: [PATCH] gpu: nvgpu: mm: fix MISRA 17.2 violation MISRA rule 17.2 prohibits functions calling themselves (recursion). Remove recursion in the function buddy_coalesce(). JIRA NVGPU-3337 Change-Id: I03ec9751688f79b4bf704f5be1c43fce6e0dbaf5 Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/2109647 Reviewed-by: Alex Waterman GVS: Gerrit_Virtual_Submit Reviewed-by: Adeel Raza Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../common/mm/allocators/buddy_allocator.c | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c b/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c index fbcc6712d..987191bfd 100644 --- a/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c @@ -367,38 +367,33 @@ static void balloc_coalesce(struct nvgpu_buddy_allocator *a, { struct nvgpu_buddy *parent; - if (buddy_is_alloced(b) || buddy_is_split(b)) { - return; + while (!buddy_is_alloced(b) && !buddy_is_split(b)) { + /* + * If both our buddy and I are both not allocated and not split + * then we can coalesce ourselves. + */ + if (b->buddy == NULL) { + return; + } + if (buddy_is_alloced(b->buddy) || buddy_is_split(b->buddy)) { + return; + } + + parent = b->parent; + + balloc_blist_rem(a, b); + balloc_blist_rem(a, b->buddy); + + buddy_clr_split(parent); + a->buddy_list_split[parent->order]--; + balloc_blist_add(a, parent); + + /* Clean up the remains. */ + nvgpu_kmem_cache_free(a->buddy_cache, b->buddy); + nvgpu_kmem_cache_free(a->buddy_cache, b); + + b = parent; } - - /* - * If both our buddy and I are both not allocated and not split then - * we can coalesce ourselves. - */ - if (b->buddy == NULL) { - return; - } - if (buddy_is_alloced(b->buddy) || buddy_is_split(b->buddy)) { - return; - } - - parent = b->parent; - - balloc_blist_rem(a, b); - balloc_blist_rem(a, b->buddy); - - buddy_clr_split(parent); - a->buddy_list_split[parent->order]--; - balloc_blist_add(a, parent); - - /* - * Recursively coalesce as far as we can go. - */ - balloc_coalesce(a, parent); - - /* Clean up the remains. */ - nvgpu_kmem_cache_free(a->buddy_cache, b->buddy); - nvgpu_kmem_cache_free(a->buddy_cache, b); } /*