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 <alexw@nvidia.com>
Reviewed-on: http://git-master/r/1169764
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Tested-by: Terje Bergstrom <tbergstrom@nvidia.com>
This commit is contained in:
Alex Waterman
2016-06-22 15:55:21 -07:00
committed by Terje Bergstrom
parent df1ff34809
commit 41ec68376f

View File

@@ -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;