From 1f27acb98396ed3337d819614a6f9537cf1c9e2a Mon Sep 17 00:00:00 2001 From: Vedashree Vidwans Date: Mon, 1 Apr 2019 14:38:41 -0700 Subject: [PATCH] gpu: nvgpu: Fix bitmap_allocator zero length bugs Currently, function nvgpu_bitmap_allocator_init() initializes bitmap with length=0 but will fail in alloc(). Function alloc() allocates len=0 bitmap and next request also starts from same address. However, rbtree only holds zero length allocation. This patch adds length = 0 check in nvgpu_bitmap_allocator_init() and alloc() functions. JIRA NVGPU-3086 Change-Id: I0936977cd193f3eba00bba28edae257e40af23bf Signed-off-by: Vedashree Vidwans Reviewed-on: https://git-master.nvidia.com/r/2087077 Reviewed-by: Nicolas Benech Reviewed-by: svc-misra-checker Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../gpu/nvgpu/common/mm/allocators/bitmap_allocator.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c index 4dc9ef73e..b7aca0da0 100644 --- a/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c @@ -209,6 +209,11 @@ static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *na, u64 len) unsigned long offs, adjusted_offs, limit; struct nvgpu_bitmap_allocator *a = bitmap_allocator(na); + if (len == 0ULL) { + alloc_dbg(na, "len = 0, Alloc failed!"); + return 0; + } + tmp_u64 = len >> a->blk_shift; nvgpu_assert(tmp_u64 <= U32_MAX); blks = (u32)tmp_u64; @@ -405,6 +410,10 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return -EINVAL; } + if (length == 0ULL) { + return -EINVAL; + } + if (base == 0ULL) { base = blk_size; length -= blk_size;