Skip to contentSkip to conversation

drm/amdgpu: Use struct_size() helper in kmalloc()

PATCH Applied Gustavo A. R. Silva 3 participants 3 messages Oct 8, 2020 – Oct 9, 2020

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

PATCH 1/1 drm/amdgpu: Use struct_size() helper in kmalloc()

Make use of the new struct_size() helper instead of the offsetof() idiom.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -2
index 5da487b64a66..30192dce7775 100644
@@ -239,8 +239,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
 	if (!old)
 		return 0;
 
-	new = kmalloc(offsetof(typeof(*new), shared[old->shared_max]),
-		      GFP_KERNEL);
+	new = kmalloc(struct_size(new, shared, old->shared_max), GFP_KERNEL);
 	if (!new)
 		return -ENOMEM;
 
Signature · 1 line
2.27.0
Applied
#1 lore raw

Applied. Thanks!

Alex

Quoted 25 lines · Gustavo A. R. Silva

Make use of the new struct_size() helper instead of the offsetof() idiom.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -3
index 5da487b64a66..30192dce7775 100644
@@ -239,8 +239,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
        if (!old)
                return 0;
 
-       new = kmalloc(offsetof(typeof(*new), shared[old->shared_max]),
-                     GFP_KERNEL);
+       new = kmalloc(struct_size(new, shared, old->shared_max), GFP_KERNEL);
        if (!new)
                return -ENOMEM;
 
--

2.27.0

Quoted 4 lines

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

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

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Gustavo A. R. Silva

Am 08.10.20 um 16:23 schrieb Gustavo A. R. Silva:

Quoted 3 lines

Make use of the new struct_size() helper instead of the offsetof() idiom.

Quoted 9 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -0
index 5da487b64a66..30192dce7775 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, · line 245

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -2
@@ -239,8 +239,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
  	if (!old)
  		return 0;
 
-	new = kmalloc(offsetof(typeof(*new), shared[old->shared_max]),
-		      GFP_KERNEL);
+	new = kmalloc(struct_size(new, shared, old->shared_max), GFP_KERNEL);
  	if (!new)
  		return -ENOMEM;
 

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