Skip to contentSkip to conversation

amd/amdgpu: use kmalloc_array to replace kmalloc with multiply

PATCH Applied Bernard Zhao 3 participants 3 messages Nov 18, 2020 – Nov 19, 2020

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

PATCH 1/1 amd/amdgpu: use kmalloc_array to replace kmalloc with multiply

Fix check_patch.pl warning:
WARNING: Prefer kmalloc_array over kmalloc with multiply +bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
WARNING: Prefer kmalloc_array over kmalloc with multiply +bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
kmalloc_array has multiply overflow check, which will be safer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -2
index d0aea5e39531..f2a0851c804f 100644
@@ -280,8 +280,8 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
 	if (!*data)
 		return -ENOMEM;
 
-	bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
-	bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
+	bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+	bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
 
 	if (!bps || !bps_bo) {
 		kfree(bps);
Signature · 1 line
2.29.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 18.11.20 um 03:55 schrieb Bernard Zhao:

Quoted 9 lines

Fix check_patch.pl warning:
WARNING: Prefer kmalloc_array over kmalloc with multiply +bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
WARNING: Prefer kmalloc_array over kmalloc with multiply +bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
kmalloc_array has multiply overflow check, which will be safer.

Not userspace controllable values, but looks cleaner anyway.

Quoted 9 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index d0aea5e39531..f2a0851c804f 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev) · line 287

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -2
@@ -280,8 +280,8 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
  	if (!*data)
  		return -ENOMEM;
 
-	bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
-	bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
+	bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+	bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
 
  	if (!bps || !bps_bo) {
  		kfree(bps);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Applied
#2 lore raw

Applied. Thanks!

Alex

Quoted 33 lines · Christian König

Am 18.11.20 um 03:55 schrieb Bernard Zhao:

Quoted 9 lines

Fix check_patch.pl warning:
WARNING: Prefer kmalloc_array over kmalloc with multiply +bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
WARNING: Prefer kmalloc_array over kmalloc with multiply +bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
kmalloc_array has multiply overflow check, which will be safer.

Not userspace controllable values, but looks cleaner anyway.

Quoted 17 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -2
index d0aea5e39531..f2a0851c804f 100644
@@ -280,8 +280,8 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
      if (!*data)
              return -ENOMEM;
 
-     bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
-     bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
+     bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+     bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev) · line 287

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
      if (!bps || !bps_bo) {
              kfree(bps);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel