Skip to content

Commit ee8b0b2

Browse files
akagoe01gregkh
authored andcommitted
drm/panthor: Fix potential memleak of vma structure
[ Upstream commit 4492d54 ] This commit addresses a memleak issue of panthor_vma (or drm_gpuva) structure in Panthor driver, that can happen if the GPU page table update operation to map the pages fail. The issue is very unlikely to occur in practice. v2: Add panthor_vm_op_ctx_return_vma() helper (Boris) v3: Add WARN_ON_ONCE (Boris) Fixes: 647810e ("drm/panthor: Add the MMU/VM logical block") Signed-off-by: Akash Goel <akash.goel@arm.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Steven Price <steven.price@arm.com> Signed-off-by: Steven Price <steven.price@arm.com> Link: https://patch.msgid.link/20251021081042.1377406-1-akash.goel@arm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ab5e8eb commit ee8b0b2

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

drivers/gpu/drm/panthor/panthor_mmu.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,20 @@ static void panthor_vm_cleanup_op_ctx(struct panthor_vm_op_ctx *op_ctx,
11461146
}
11471147
}
11481148

1149+
static void
1150+
panthor_vm_op_ctx_return_vma(struct panthor_vm_op_ctx *op_ctx,
1151+
struct panthor_vma *vma)
1152+
{
1153+
for (u32 i = 0; i < ARRAY_SIZE(op_ctx->preallocated_vmas); i++) {
1154+
if (!op_ctx->preallocated_vmas[i]) {
1155+
op_ctx->preallocated_vmas[i] = vma;
1156+
return;
1157+
}
1158+
}
1159+
1160+
WARN_ON_ONCE(1);
1161+
}
1162+
11491163
static struct panthor_vma *
11501164
panthor_vm_op_ctx_get_vma(struct panthor_vm_op_ctx *op_ctx)
11511165
{
@@ -2085,8 +2099,10 @@ static int panthor_gpuva_sm_step_map(struct drm_gpuva_op *op, void *priv)
20852099
ret = panthor_vm_map_pages(vm, op->map.va.addr, flags_to_prot(vma->flags),
20862100
op_ctx->map.sgt, op->map.gem.offset,
20872101
op->map.va.range);
2088-
if (ret)
2102+
if (ret) {
2103+
panthor_vm_op_ctx_return_vma(op_ctx, vma);
20892104
return ret;
2105+
}
20902106

20912107
/* Ref owned by the mapping now, clear the obj field so we don't release the
20922108
* pinning/obj ref behind GPUVA's back.

0 commit comments

Comments
 (0)