AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: "Kuehling, Felix" <felix.kuehling@amd.com>,
	Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>,
	Sunil Khatri <sunil.khatri@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [Patch v1] drm/amdgpu: null check for hmm_pfns ptr before freeing it
Date: Mon, 27 Oct 2025 15:28:16 +0100	[thread overview]
Message-ID: <f8ccd8cb-8ef3-4c6c-b512-a469da7f5512@amd.com> (raw)
In-Reply-To: <a1c87ae7-9f8d-4fb7-a141-c285776d76b0@amd.com>



On 10/23/25 17:30, Kuehling, Felix wrote:
> 
> On 2025-10-23 03:48, Arunpravin Paneer Selvam wrote:
>> Acked-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
>>
>> Regards,
>> Arun.
>> On 10/23/2025 12:28 PM, Sunil Khatri wrote:
>>> Due to low memory or when num of pages is too big to be
>>> accomodated, allocation could fail for pfn's.
>>>
>>> Chekc hmm_pfns for NULL before calling the kvfree for the it.
>>>
>>> Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
>>> ---
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 6 +++++-
>>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c
>>> index d6f903a2d573..6ac206e2bc46 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c
>>> @@ -286,7 +286,11 @@ void amdgpu_hmm_range_free(struct amdgpu_hmm_range *range)
>>>       if (!range)
>>>           return;
>>>   -    kvfree(range->hmm_range.hmm_pfns);
>>> +    if (range->hmm_range.hmm_pfns) {
>>> +        kvfree(range->hmm_range.hmm_pfns);
>>> +        range->hmm_range.hmm_pfns = NULL;
>>> +    }
> 
> NULL-checks before kfree and friends are unnecessary. There are actually static checkers that complain about such unnecessary NULL-checks. For example, see https://lkml.org/lkml/2024/8/11/168.
> 
> The same is also true for the standard libc free in usermode: https://stackoverflow.com/questions/1912325/checking-for-null-before-calling-free.
> 
> Finally, setting range->hmm_range.hmm_pfns = NULL is also unnecessary because you're about to free the whole range structure anyway.

Agree completely with Felix.

Sunil why do you think that this is necessary and blocking KFD for some reason?

Regards,
Christian.

> 
> Regards,
>   Felix
> 
> 
>>> +
>>>       amdgpu_bo_unref(&range->bo);
>>>       kfree(range);
>>>   }
>>


  reply	other threads:[~2025-10-27 14:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-23  6:58 [Patch v1] drm/amdgpu: null check for hmm_pfns ptr before freeing it Sunil Khatri
2025-10-23  7:48 ` Arunpravin Paneer Selvam
2025-10-23 15:30   ` Kuehling, Felix
2025-10-27 14:28     ` Christian König [this message]
2025-10-27 14:40       ` Khatri, Sunil
2025-10-28  8:53         ` Christian König

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=f8ccd8cb-8ef3-4c6c-b512-a469da7f5512@amd.com \
    --to=christian.koenig@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=felix.kuehling@amd.com \
    --cc=sunil.khatri@amd.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