From eb473aa0b1ad2a65195950907438a0de6e53d527 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Thu, 30 Aug 2018 14:05:25 +0530 Subject: gpu: nvgpu: fix crash with uninitialized comptag allocator If gk20a_comptaglines_alloc() is called with an uninitialized comptag allocator we right now see a kernel panic like this [ 445.097931] [] __mutex_lock_slowpath+0xe0/0x188 [ 445.104275] [] mutex_lock+0x50/0x68 [ 445.109773] [] gk20a_comptaglines_alloc+0x30/0x98 [nvgpu] [ 445.117169] [] gk20a_alloc_or_get_comptags+0xe4/0x140 [nvgpu] [ 445.124910] [] nvgpu_vm_map+0x414/0x7b8 [nvgpu] [ 445.131433] [] nvgpu_vm_map_linux+0x114/0x1e8 [nvgpu] [ 445.138475] [] nvgpu_vm_map_buffer+0x150/0x238 [nvgpu] [ 445.145605] [] gk20a_as_dev_ioctl+0x30c/0xa78 [nvgpu] [ 445.152473] [] do_vfs_ioctl+0xc4/0x8f8 Fix this by checking explicitly that comptag allocator is initialized in gk20a_comptaglines_alloc() and gk20a_comptaglines_free() Bug 2171567 Change-Id: Iaac6d77e40a8aaa01f2bacbe0cb54ec447100075 Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/1805170 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom Reviewed-by: Seshendra Gadagottu Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/comptags.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/mm/comptags.c b/drivers/gpu/nvgpu/common/mm/comptags.c index 334236ec..3bde3a53 100644 --- a/drivers/gpu/nvgpu/common/mm/comptags.c +++ b/drivers/gpu/nvgpu/common/mm/comptags.c @@ -32,6 +32,10 @@ int gk20a_comptaglines_alloc(struct gk20a_comptag_allocator *allocator, unsigned long addr; int err = 0; + if (allocator->size == 0UL) { + return -EINVAL; + } + nvgpu_mutex_acquire(&allocator->lock); addr = bitmap_find_next_zero_area(allocator->bitmap, allocator->size, 0, len, 0); @@ -53,6 +57,10 @@ void gk20a_comptaglines_free(struct gk20a_comptag_allocator *allocator, /* number zero is reserved; bitmap base is 1 */ u32 addr = offset - 1U; + if (allocator->size == 0UL) { + return; + } + WARN_ON(offset == 0U); WARN_ON(addr > allocator->size); WARN_ON(addr + len > allocator->size); -- cgit v1.2.2