Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 9cca48fa4f89 ("drm/panthor: Add the heap logical block")
Reported-by: Eric Smith <eric.smith@collabora.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Tested-by: Eric Smith <eric.smith@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240502165158.1458959-5-boris.brezillon@collabora.com

+3 -2
+3 -2
drivers/gpu/drm/panthor/panthor_heap.c
··· 323 323 if (!pool->vm) { 324 324 ret = -EINVAL; 325 325 } 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); 327 328 if (!ret) { 328 329 void *gpu_ctx = panthor_get_heap_ctx(pool, id); 329 330 ··· 544 543 pool->vm = vm; 545 544 pool->ptdev = ptdev; 546 545 init_rwsem(&pool->lock); 547 - xa_init_flags(&pool->xa, XA_FLAGS_ALLOC1); 546 + xa_init_flags(&pool->xa, XA_FLAGS_ALLOC); 548 547 kref_init(&pool->refcount); 549 548 550 549 pool->gpu_contexts = panthor_kernel_bo_create(ptdev, vm, bosize,