Skip to content

Commit 70db83e

Browse files
James Flowersalexdeucher
authored andcommitted
drm/amd/display: Use kmalloc_array() instead of kmalloc()
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. This could lead to buffer overflow in code similar to the memcpy in amdgpu_dm_plane_add_modifier(). Signed-off-by: James Flowers <bold.zone2373@fastmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 39203f5 commit 70db83e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void amdgpu_dm_plane_add_modifier(uint64_t **mods, uint64_t *size, uint64
146146

147147
if (*cap - *size < 1) {
148148
uint64_t new_cap = *cap * 2;
149-
uint64_t *new_mods = kmalloc(new_cap * sizeof(uint64_t), GFP_KERNEL);
149+
uint64_t *new_mods = kmalloc_array(new_cap, sizeof(uint64_t), GFP_KERNEL);
150150

151151
if (!new_mods) {
152152
kfree(*mods);
@@ -732,7 +732,7 @@ static int amdgpu_dm_plane_get_plane_modifiers(struct amdgpu_device *adev, unsig
732732
if (adev->family < AMDGPU_FAMILY_AI)
733733
return 0;
734734

735-
*mods = kmalloc(capacity * sizeof(uint64_t), GFP_KERNEL);
735+
*mods = kmalloc_array(capacity, sizeof(uint64_t), GFP_KERNEL);
736736

737737
if (plane_type == DRM_PLANE_TYPE_CURSOR) {
738738
amdgpu_dm_plane_add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_LINEAR);

0 commit comments

Comments
 (0)