Skip to contentSkip to conversation

drm/lima: Drop the BO references if drm_sched_job_init() fails

PATCH New Suyuan Wang 1 participant 1 message Nov 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/lima: Drop the BO references if drm_sched_job_init() fails

From: Suyuan Wang <[email protected]>

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")

---
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(+)
drivers/gpu/drm/lima/lima_sched.c +2 -0
index fee595b9629a..53d597850782 100644
@@ -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;
 	}