Skip to content

Commit 8e43b1e

Browse files
committed
drm/panthor: Fix an off-by-one in the heap context retrieval logic
The heap ID is used to index the heap context pool, and allocating in the [1:MAX_HEAPS_PER_POOL] leads to an off-by-one. This was originally to avoid returning a zero heap handle, but given the handle is formed with (vm_id << 16) | heap_id, with vm_id > 0, we already can't end up with a valid heap handle that's zero. v4: - s/XA_FLAGS_ALLOC1/XA_FLAGS_ALLOC/ v3: - Allocate in the [0:MAX_HEAPS_PER_POOL-1] range v2: - New patch Fixes: 9cca48f ("drm/panthor: Add the heap logical block") Reported-by: Eric Smith <[email protected]> Signed-off-by: Boris Brezillon <[email protected]> Tested-by: Eric Smith <[email protected]> Reviewed-by: Steven Price <[email protected]> Reviewed-by: Liviu Dudau <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 69a4299 commit 8e43b1e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/gpu/drm/panthor/panthor_heap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ int panthor_heap_create(struct panthor_heap_pool *pool,
323323
if (!pool->vm) {
324324
ret = -EINVAL;
325325
} else {
326-
ret = xa_alloc(&pool->xa, &id, heap, XA_LIMIT(1, MAX_HEAPS_PER_POOL), GFP_KERNEL);
326+
ret = xa_alloc(&pool->xa, &id, heap,
327+
XA_LIMIT(0, MAX_HEAPS_PER_POOL - 1), GFP_KERNEL);
327328
if (!ret) {
328329
void *gpu_ctx = panthor_get_heap_ctx(pool, id);
329330

@@ -543,7 +544,7 @@ panthor_heap_pool_create(struct panthor_device *ptdev, struct panthor_vm *vm)
543544
pool->vm = vm;
544545
pool->ptdev = ptdev;
545546
init_rwsem(&pool->lock);
546-
xa_init_flags(&pool->xa, XA_FLAGS_ALLOC1);
547+
xa_init_flags(&pool->xa, XA_FLAGS_ALLOC);
547548
kref_init(&pool->refcount);
548549

549550
pool->gpu_contexts = panthor_kernel_bo_create(ptdev, vm, bosize,

0 commit comments

Comments
 (0)