From 1deb1fa176da157da4e19755ea5386c29e9ccc68 Mon Sep 17 00:00:00 2001 From: Nicolas Benech Date: Thu, 13 Jun 2019 10:29:27 -0400 Subject: [PATCH] gpu: nvgpu: unit: bitmap_allocator: fix init crashes While fixing CERT-C issues in the bitmap_allocator, a number of asserts were added. In particular, if blk_size is 0 it will cause a BUG(). Within the bitmap_allocator unit test, the init will try to set blk_size to 0 to make sure it fails. Now the failure is a BUG(), not a return code. So this fix adds EXPECT_BUG where needed. JIRA NVGPU-906 Change-Id: I62ae725e494a7cf561ac8cac7685cffbbc8de38e Signed-off-by: Nicolas Benech Reviewed-on: https://git-master.nvidia.com/r/2135823 Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../mm/allocators/bitmap_allocator/bitmap_allocator.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c b/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c index f86b3997c..e5d01f952 100644 --- a/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c +++ b/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c @@ -303,8 +303,8 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m, } /* base = 0, length = 0, blk_size = 0 */ - if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", 0ULL, 0ULL, 0ULL, - 0ULL, flags, BITMAP_ALLOCATOR) == 0) { + if (!EXPECT_BUG(nvgpu_allocator_init(g, na, NULL, "test_bitmap", 0ULL, + 0ULL, 0ULL, 0ULL, flags, BITMAP_ALLOCATOR))) { na->ops->fini(na); unit_return_fail(m, "bitmap inited despite blk_size = base = length = 0\n"); @@ -314,9 +314,9 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m, * blk_size = 0 * Since base and length are not aligned with 0, init fails */ - if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length, - 0ULL, 0ULL, flags, BITMAP_ALLOCATOR) == 0) { - unit_return_fail(m, "bitmap init failed for blk_size=0\n"); + if (!EXPECT_BUG(nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, + length, 0ULL, 0ULL, flags, BITMAP_ALLOCATOR))) { + unit_return_fail(m, "bitmap inited despite blk_size=0\n"); } /* Odd blk_size */