mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Kuehling, Felix" <felix.kuehling@amd.com>
To: Rahul Kumar <rk0006818@gmail.com>,
	alexander.deucher@amd.com, christian.koenig@amd.com,
	airlied@gmail.com, simona@ffwll.ch,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org
Subject: Re: [PATCH] drm/amdgpu: Use kmalloc_array() instead of kmalloc()
Date: Wed, 17 Sep 2025 14:25:23 -0400	[thread overview]
Message-ID: <f782159b-ad3f-4d0c-8476-50a701bf29e6@amd.com> (raw)
In-Reply-To: <20250916092949.4118999-1-rk0006818@gmail.com>

On 2025-09-16 05:29, Rahul Kumar wrote:
> Documentation/process/deprecated.rst recommends against the use of
> kmalloc with dynamic size calculations due to the risk of overflow and
> smaller allocation being made than the caller was expecting.
>
> Replace kmalloc() with kmalloc_array() in amdgpu_amdkfd_gfx_v10.c
> to make the intended allocation size clearer and avoid potential
> overflow issues.
>
> Signed-off-by: Rahul Kumar <rk0006818@gmail.com>

The patch looks good to me. Looks like this got fixed in GFX9 and older 
but that didn't make it into GFX10 and newer implementations that were 
probably on some internal branch at the time. For the sake of 
completeness and consistency the same fix should be applied to 
amdgpu_amdkfd_gfx_v10_3.c, amdgpu_amdkfd_gfx_v11.c and 
amdgpu_amdkfd_gfx_v12.c. Can you send an updated patch that includes 
them as well?

Thanks,
   Felix


> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
> index 04ef0ca10541..0239114fb6c4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
> @@ -352,7 +352,7 @@ static int kgd_hqd_dump(struct amdgpu_device *adev,
>   		(*dump)[i++][1] = RREG32_SOC15_IP(GC, addr);		\
>   	} while (0)
>   
> -	*dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
> +	*dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
>   	if (*dump == NULL)
>   		return -ENOMEM;
>   
> @@ -449,7 +449,7 @@ static int kgd_hqd_sdma_dump(struct amdgpu_device *adev,
>   #undef HQD_N_REGS
>   #define HQD_N_REGS (19+6+7+10)
>   
> -	*dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
> +	*dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
>   	if (*dump == NULL)
>   		return -ENOMEM;
>   

  reply	other threads:[~2025-09-17 18:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16  9:29 Rahul Kumar
2025-09-17 18:25 ` Kuehling, Felix [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-06-16  2:55 [PATCH] drm/amdgpu: use " Yunshui Jiang
2025-06-16  3:14 ` Matthew Wilcox
2025-06-16  7:30 ` kernel test robot

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=f782159b-ad3f-4d0c-8476-50a701bf29e6@amd.com \
    --to=felix.kuehling@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=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rk0006818@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.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

all inboxes | Powered by JetHome®