]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amd/display: Use kmalloc_array() instead of kmalloc()
authorJames Flowers <bold.zone2373@fastmail.com>
Sat, 13 Sep 2025 05:19:52 +0000 (22:19 -0700)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 16 Sep 2025 21:47:11 +0000 (17:47 -0400)
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>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c

index eef51652ca3560301dcfe92c80b5a81f442a049d..08f629c64df3cd9bcdb517024fdf13802d8e62ec 100644 (file)
@@ -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);