Skip to contentSkip to conversation

drm/amd/amdgpu: use kmalloc_array instead of kmalloc

PATCH In review Moktar SELLAMI 2 participants 2 messages Sep 22, 2025 – Sep 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/amdgpu: use kmalloc_array instead of kmalloc

Replace kmalloc -> kmalloc_array in drm/amd/amdgpu/amdgpu_ras.c .

As per said in the Documentation/process/deprecated.rst, dynamic size calculation should not be performed in memory allocator function arguments due to the risk of overflow.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -1
index 540817e296da..8dbb9e349a8e 100644
@@ -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(data->count, sizeof(struct ras_badpage), GFP_KERNEL);
 	if (!*bps) {
 		ret = -ENOMEM;
 		goto out;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · Moktar SELLAMI

Replace kmalloc -> kmalloc_array in drm/amd/amdgpu/amdgpu_ras.c .

As per said in the Documentation/process/deprecated.rst, dynamic size calculation should not be performed in memory allocator function arguments due to the risk of overflow.

Thanks for the patch. Some already supplied a similar patch which was applied.

Alex

Quoted 20 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -2
index 540817e296da..8dbb9e349a8e 100644
@@ -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(data->count, sizeof(struct ras_badpage), GFP_KERNEL);
        if (!*bps) {
                ret = -ENOMEM;
                goto out;
--

2.34.1