mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Lazar, Lijo" <lijo.lazar@amd.com>
To: "Christian König" <christian.koenig@amd.com>,
	"Zilin Guan" <zilin@seu.edu.cn>,
	alexander.deucher@amd.com
Cc: airlied@gmail.com, simona@ffwll.ch, Hawking.Zhang@amd.com,
	Prike.Liang@amd.com, le.ma@amd.com,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, jianhao.xu@seu.edu.cn
Subject: Re: [PATCH] drm/amdgpu: Use kvfree instead of kfree in amdgpu_gmc_get_nps_memranges()
Date: Thu, 29 Jan 2026 15:33:17 +0530	[thread overview]
Message-ID: <b814cdb3-ce83-4db1-b512-c69cc54bda4c@amd.com> (raw)
In-Reply-To: <031ae8a1-5608-4993-91c2-c5945bd6f7ad@amd.com>



On 29-Jan-26 3:00 PM, Christian König wrote:
> On 1/29/26 10:05, Zilin Guan wrote:
>> amdgpu_discovery_get_nps_info() internally allocates memory for ranges
>> using kvcalloc(), which may use vmalloc() for large allocation. Using
>> kfree() to release vmalloc memory will lead to a memory corruption.
>>
>> Use kvfree() to safely handle both kmalloc and vmalloc allocations.
>>
>> Compile tested only. Issue found using a prototype static analysis tool
>> and code review.
>>
>> Fixes: b194d21b9bcc ("drm/amdgpu: Use NPS ranges from discovery table")
>> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> 
> Good catch!
> 
> But i think we rather need to question why amdgpu_discovery_get_nps_info() is using kvcalloc()? I have strong doubts that we need vmalloc() here.
> 

Yes, vmalloc is enough. That change can be made separately or modified 
along with this.

As for this as a standalone change -
	Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>

Thanks,
Lijo


> Regards,
> Christian.
> 
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
>> index 7e623f91f2d7..cb0d1ac148e9 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
>> @@ -1382,7 +1382,7 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,
>>   	if (!*exp_ranges)
>>   		*exp_ranges = range_cnt;
>>   err:
>> -	kfree(ranges);
>> +	kvfree(ranges);
>>   
>>   	return ret;
>>   }
> 


  reply	other threads:[~2026-01-29 10:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29  9:05 Zilin Guan
2026-01-29  9:30 ` Christian König
2026-01-29 10:03   ` Lazar, Lijo [this message]
2026-02-02 14:58     ` Alex Deucher

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=b814cdb3-ce83-4db1-b512-c69cc54bda4c@amd.com \
    --to=lijo.lazar@amd.com \
    --cc=Hawking.Zhang@amd.com \
    --cc=Prike.Liang@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=le.ma@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=zilin@seu.edu.cn \
    /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®