[PATCH] drm/lima: Drop the BO references if drm_sched_job_init() fails
From: Suyuan Wang via B4 Relay
Date: Mon Nov 23 2026 - 23:39:26 EST
From: Suyuan Wang <stevewong@xxxxxxxxxxx>
lima_sched_task_init() takes a reference on every BO of the task before
it calls drm_sched_job_init():
for (i = 0; i < num_bos; i++)
drm_gem_object_get(&bos[i]->base.base);
err = drm_sched_job_init(&task->base, &context->base, 1, vm,
drm_client_id);
if (err) {
kfree(task->bos);
return err;
}
If drm_sched_job_init() fails (it can return -ENOMEM), only the array is
freed. lima_gem_submit() then goes to err_out1, which does not call
lima_sched_task_fini(), so these extra references are never dropped and
the BOs are not freed even after all other references are gone. This
can happen on every submit ioctl.
Put the references before freeing the array.
Found with a static analysis tool and checked by hand.
Fixes: a1d2a6339961 ("drm/lima: driver for ARM Mali4xx GPUs")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
Compile tested on arm64 (W=1). I don't have the hardware.
---
drivers/gpu/drm/lima/lima_sched.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/lima/lima_sched.c b/drivers/gpu/drm/lima/lima_sched.c
index fee595b9629a..53d597850782 100644
--- a/drivers/gpu/drm/lima/lima_sched.c
+++ b/drivers/gpu/drm/lima/lima_sched.c
@@ -130,6 +130,8 @@ int lima_sched_task_init(struct lima_sched_task *task,
err = drm_sched_job_init(&task->base, &context->base, 1, vm,
drm_client_id);
if (err) {
+ for (i = 0; i < num_bos; i++)
+ drm_gem_object_put(&bos[i]->base.base);
kfree(task->bos);
return err;
}