dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Tomeu Vizoso <tomeu@tomeuvizoso.net>
To: Li Qiang <liqiang01@kylinos.cn>
Cc: ogabbay@kernel.org, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/rocket: Add scheds pointer to file_priv and fix memory leaks
Date: Tue, 9 Dec 2025 08:04:13 +0100	[thread overview]
Message-ID: <CAAObsKBPsPpsmmF1EmPLw7-2o1Zq9C0jgkkHpEh0WSq5mWj++A@mail.gmail.com> (raw)
In-Reply-To: <20251107024620.912403-1-liqiang01@kylinos.cn>

Are you sure of this? The list should be freed in rocket_job_close(),
just before freeing the entity.

Regards,

Tomeu

On Fri, Nov 7, 2025 at 3:46 AM Li Qiang <liqiang01@kylinos.cn> wrote:
>
> The rocket driver allocates an array of struct drm_gpu_scheduler pointers
> for each file via kmalloc_array() in rocket_job_open(). However, the
> allocated memory was not stored in rocket_file_priv and therefore never
> freed on file close, leading to a memory leak.
>
> This patch introduces a new `scheds` field in struct rocket_file_priv to
> store the allocated pointer array, and frees it properly in
> rocket_job_close() after the scheduler entity is destroyed.
>
> This ensures correct lifetime tracking of scheduler arrays and resolves
> the leak detected by code review and potential KASAN reports.
>
> Signed-off-by: Li Qiang <liqiang01@kylinos.cn>
> ---
>  drivers/accel/rocket/rocket_drv.h |  1 +
>  drivers/accel/rocket/rocket_job.c | 10 +++++++++-
>  2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/accel/rocket/rocket_drv.h b/drivers/accel/rocket/rocket_drv.h
> index 2c673bb99ccc..759a08596dad 100644
> --- a/drivers/accel/rocket/rocket_drv.h
> +++ b/drivers/accel/rocket/rocket_drv.h
> @@ -24,6 +24,7 @@ struct rocket_file_priv {
>         struct mutex mm_lock;
>
>         struct drm_sched_entity sched_entity;
> +       struct drm_gpu_scheduler **scheds;
>  };
>
>  struct rocket_iommu_domain *rocket_iommu_domain_get(struct rocket_file_priv *rocket_priv);
> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index acd606160dc9..820d96f010f2 100644
> --- a/drivers/accel/rocket/rocket_job.c
> +++ b/drivers/accel/rocket/rocket_job.c
> @@ -502,6 +502,9 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
>         unsigned int core;
>         int ret;
>
> +       if (unlikely(!scheds))
> +               return -ENOMEM;
> +
>         for (core = 0; core < rdev->num_cores; core++)
>                 scheds[core] = &rdev->cores[core].sched;
>
> @@ -509,8 +512,12 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
>                                     DRM_SCHED_PRIORITY_NORMAL,
>                                     scheds,
>                                     rdev->num_cores, NULL);
> -       if (WARN_ON(ret))
> +       if (WARN_ON(ret)) {
> +               kfree(scheds);
>                 return ret;
> +       }
> +
> +       rocket_priv->scheds = scheds;
>
>         return 0;
>  }
> @@ -520,6 +527,7 @@ void rocket_job_close(struct rocket_file_priv *rocket_priv)
>         struct drm_sched_entity *entity = &rocket_priv->sched_entity;
>
>         kfree(entity->sched_list);
> +       kfree(rocket_priv->scheds);
>         drm_sched_entity_destroy(entity);
>  }
>
> --
> 2.25.1
>

      parent reply	other threads:[~2025-12-09  7:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07  2:46 [PATCH] drm/rocket: Add scheds pointer to file_priv and fix memory leaks Li Qiang
2025-11-25 17:34 ` Markus Elfring
2025-12-09  7:04 ` Tomeu Vizoso [this message]

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=CAAObsKBPsPpsmmF1EmPLw7-2o1Zq9C0jgkkHpEh0WSq5mWj++A@mail.gmail.com \
    --to=tomeu@tomeuvizoso.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liqiang01@kylinos.cn \
    --cc=ogabbay@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).