mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: mripard@kernel.org, maarten.lankhorst@linux.intel.com,
	 airlied@gmail.com, tzimmermann@suse.de, simona@ffwll.ch,
	yuq825@gmail.com
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	 lima@lists.freedesktop.org
Subject: [PATCH] drm/lima: Drop the BO references if drm_sched_job_init() fails
Date: Tue, 24 Nov 2026 04:39:15 +0000	[thread overview]
Message-ID: <20261124-lima-task-init-v1-1-2f6129257703@gmail.com> (raw)

From: Suyuan Wang <stevewong@hust.edu.cn>

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@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
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;
 	}





                 reply	other threads:[~2026-11-24  4:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124-lima-task-init-v1-1-2f6129257703@gmail.com \
    --to=devnull+shyckless.gmail.com@kernel.org \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lima@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=shyckless@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    --cc=yuq825@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®