All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: Andrew Martin <Andrew.Martin@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdkfd: Dereference null return value
Date: Thu, 28 Nov 2024 11:55:23 -0500	[thread overview]
Message-ID: <67f491ae-059a-49fd-99d3-bcd156085e89@amd.com> (raw)
In-Reply-To: <20241128162604.966580-1-Andrew.Martin@amd.com>


On 2024-11-28 11:26, Andrew Martin wrote:
> In the function pqm_uninit there is a call-assignment of "pdd =
> kfd_get_process_device_data" which could be null, and this value was
> later dereferenced without checking.
> 
> Signed-off-by: Andrew Martin <Andrew.Martin@amd.com>

This seems to fix a bug introduced by a previous patch. Please add a Fixes tag for that:

Fixes: fb91065851cd ("drm/amdkfd: Refactor queue wptr_bo GART mapping")

> ---
>  .../drm/amd/amdkfd/kfd_process_queue_manager.c   | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> index c76db22a1000..808c447879c0 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> @@ -212,13 +212,21 @@ static void pqm_clean_queue_resource(struct process_queue_manager *pqm,
>  void pqm_uninit(struct process_queue_manager *pqm)
>  {
>  	struct process_queue_node *pqn, *next;
> -	struct kfd_process_device *pdd;
>  
>  	list_for_each_entry_safe(pqn, next, &pqm->queues, process_queue_list) {
>  		if (pqn->q) {
> -			pdd = kfd_get_process_device_data(pqn->q->device, pqm->process);
> -			kfd_queue_unref_bo_vas(pdd, &pqn->q->properties);
> -			kfd_queue_release_buffers(pdd, &pqn->q->properties);
> +			struct kfd_process_device *pdd =
> +				kfd_get_process_device_data(
> +					pqn->q->device,
> +					pqm->process);
> +			if (pdd) {

checkpatch.pl will complain without an empty line after the variable declaration.

> +				kfd_queue_unref_bo_vas(
> +					pdd,
> +					&pqn->q->properties);
> +				kfd_queue_release_buffers(
> +					pdd,
> +					&pqn->q->properties);
> +			}

I think it should be impossible for pdd to be NULL here. Without a PDD, the queue could not have been created in the first place. If we want to add a NULL check here, we should make that a WARN or WARN_ON because it would indicate some serious bug somewhere. The result would be a memory leak here, so we need to warn about that.

Regards,
  Felix

>  			pqm_clean_queue_resource(pqm, pqn);
>  		}
>  


      reply	other threads:[~2024-11-28 16:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28 16:26 [PATCH] drm/amdkfd: Dereference null return value Andrew Martin
2024-11-28 16:55 ` Felix Kuehling [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=67f491ae-059a-49fd-99d3-bcd156085e89@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=Andrew.Martin@amd.com \
    --cc=amd-gfx@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.