From 41ec68376ff4291f9aa50df014439ce462a8e87f Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 22 Jun 2016 15:55:21 -0700 Subject: gpu: nvgpu: Handle allocators with a base of 0 When an allocator is created with a base of 0 the first allocated block could well be 0. This appears to be an error since gk20a_balloc() normally returns 0 for error cases. This patch removes one block from the allocatable resources when base is set to 0 so that code using gk20a_balloc() does not get tricked into thinking valid allocations are OOM cases. Change-Id: I641642d3f790c4c7860d0d1381f4db6f4f72e709 Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1169764 Reviewed-by: Terje Bergstrom Tested-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/gk20a_allocator.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c index fd721709..d3a9202b 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c @@ -285,6 +285,15 @@ int __gk20a_allocator_init(struct gk20a_allocator *a, a->blk_size = blk_size; a->blk_shift = __ffs(blk_size); + /* + * If base is 0 then modfy base to be the size of one block so that we + * can return errors by returning addr == 0. + */ + if (a->base == 0) { + a->base = a->blk_size; + a->length -= a->blk_size; + } + /* blk_size must be greater than 0 and a power of 2. */ if (blk_size == 0) return -EINVAL; -- cgit v1.2.2