From: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
To: "Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Harry Wentland" <harry.wentland@amd.com>,
"Leo Li" <sunpeng.li@amd.com>,
"Rodrigo Siqueira" <siqueira@igalia.com>,
"Tao Zhou" <tao.zhou1@amd.com>,
"Hawking Zhang" <Hawking.Zhang@amd.com>,
ganglxie <ganglxie@amd.com>, "Lijo Lazar" <lijo.lazar@amd.com>,
"Candice Li" <candice.li@amd.com>,
"Victor Skvortsov" <victor.skvortsov@amd.com>,
"Roman Li" <roman.li@amd.com>, "Alvin Lee" <Alvin.Lee2@amd.com>,
"Karthi Kandasamy" <karthi.kandasamy@amd.com>,
"David Rosca" <david.rosca@amd.com>,
"Marek Olšák" <marek.olsak@amd.com>,
"Jocelyn Falempe" <jfalempe@redhat.com>,
"André Almeida" <andrealmeid@igalia.com>,
"Mario Limonciello" <mario.limonciello@amd.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, khalid@kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
bhanuseshukumar@gmail.com
Subject: [PATCH] drm: amd: Use kmalloc_array to prevent overflow of dynamic size calculation
Date: Thu, 2 Oct 2025 07:52:41 +0530 [thread overview]
Message-ID: <20251002022241.77823-1-bhanuseshukumar@gmail.com> (raw)
Use kmalloc_array to avoid potential overflow during dynamic size calculation
inside kmalloc.
Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
---
Note:
Patch is verified for compilation.
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++--
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index 540817e296da..642addf70466 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -2566,7 +2566,7 @@ static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
goto out;
}
- *bps = kmalloc(sizeof(struct ras_badpage) * data->count, GFP_KERNEL);
+ *bps = kmalloc_array(sizeof(struct ras_badpage), data->count, GFP_KERNEL);
if (!*bps) {
ret = -ENOMEM;
goto out;
@@ -2722,7 +2722,7 @@ static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
unsigned int old_space = data->count + data->space_left;
unsigned int new_space = old_space + pages;
unsigned int align_space = ALIGN(new_space, 512);
- void *bps = kmalloc(align_space * sizeof(*data->bps), GFP_KERNEL);
+ void *bps = kmalloc_array(align_space, sizeof(*data->bps), GFP_KERNEL);
if (!bps) {
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
index 3d2f8eedeef2..e027798ece03 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -146,7 +146,7 @@ static void amdgpu_dm_plane_add_modifier(uint64_t **mods, uint64_t *size, uint64
if (*cap - *size < 1) {
uint64_t new_cap = *cap * 2;
- uint64_t *new_mods = kmalloc(new_cap * sizeof(uint64_t), GFP_KERNEL);
+ uint64_t *new_mods = kmalloc_array(new_cap, sizeof(uint64_t), GFP_KERNEL);
if (!new_mods) {
kfree(*mods);
@@ -732,7 +732,7 @@ static int amdgpu_dm_plane_get_plane_modifiers(struct amdgpu_device *adev, unsig
if (adev->family < AMDGPU_FAMILY_AI)
return 0;
- *mods = kmalloc(capacity * sizeof(uint64_t), GFP_KERNEL);
+ *mods = kmalloc_array(capacity, sizeof(uint64_t), GFP_KERNEL);
if (plane_type == DRM_PLANE_TYPE_CURSOR) {
amdgpu_dm_plane_add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_LINEAR);
--
2.34.1
next reply other threads:[~2025-10-02 2:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-02 2:22 Bhanu Seshu Kumar Valluri [this message]
2025-10-02 23:19 ` [PATCH] drm: amd: Use kmalloc_array to prevent overflow of dynamic size calculation 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=20251002022241.77823-1-bhanuseshukumar@gmail.com \
--to=bhanuseshukumar@gmail.com \
--cc=Alvin.Lee2@amd.com \
--cc=Hawking.Zhang@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andrealmeid@igalia.com \
--cc=candice.li@amd.com \
--cc=christian.koenig@amd.com \
--cc=david.hunter.linux@gmail.com \
--cc=david.rosca@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ganglxie@amd.com \
--cc=harry.wentland@amd.com \
--cc=jfalempe@redhat.com \
--cc=karthi.kandasamy@amd.com \
--cc=khalid@kernel.org \
--cc=lijo.lazar@amd.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marek.olsak@amd.com \
--cc=mario.limonciello@amd.com \
--cc=roman.li@amd.com \
--cc=simona@ffwll.ch \
--cc=siqueira@igalia.com \
--cc=skhan@linuxfoundation.org \
--cc=sunpeng.li@amd.com \
--cc=tao.zhou1@amd.com \
--cc=victor.skvortsov@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