Skip to content

Commit 98ae402

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 6e17555 commit 98ae402

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
@@ -1139,6 +1139,20 @@ static void panthor_vm_cleanup_op_ctx(struct panthor_vm_op_ctx *op_ctx,
11391139
}
11401140
}
11411141

1142+
static void
1143+
panthor_vm_op_ctx_return_vma(struct panthor_vm_op_ctx *op_ctx,
1144+
struct panthor_vma *vma)
1145+
{
1146+
for (u32 i = 0; i < ARRAY_SIZE(op_ctx->preallocated_vmas); i++) {
1147+
if (!op_ctx->preallocated_vmas[i]) {
1148+
op_ctx->preallocated_vmas[i] = vma;
1149+
return;
1150+
}
1151+
}
1152+
1153+
WARN_ON_ONCE(1);
1154+
}
1155+
11421156
static struct panthor_vma *
11431157
panthor_vm_op_ctx_get_vma(struct panthor_vm_op_ctx *op_ctx)
11441158
{
@@ -2037,8 +2051,10 @@ static int panthor_gpuva_sm_step_map(struct drm_gpuva_op *op, void *priv)
20372051
ret = panthor_vm_map_pages(vm, op->map.va.addr, flags_to_prot(vma->flags),
20382052
op_ctx->map.sgt, op->map.gem.offset,
20392053
op->map.va.range);
2040-
if (ret)
2054+
if (ret) {
2055+
panthor_vm_op_ctx_return_vma(op_ctx, vma);
20412056
return ret;
2057+
}
20422058

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

0 commit comments

Comments
 (0)