dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] drm/amdgpu: Use struct_size() helper in kmalloc()
@ 2020-10-08 14:23 Gustavo A. R. Silva
  2020-10-08 17:22 ` Alex Deucher
  2020-10-09  7:07 ` Christian König
  0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2020-10-08 14:23 UTC (permalink / raw)
  To: Felix Kuehling, Alex Deucher, Christian König, David Airlie,
	Daniel Vetter
  Cc: Gustavo A. R. Silva, linux-hardening, dri-devel, amd-gfx, linux-kernel

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

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 5da487b64a66..30192dce7775 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] drm/amdgpu: Use struct_size() helper in kmalloc()
  2020-10-08 14:23 [PATCH][next] drm/amdgpu: Use struct_size() helper in kmalloc() Gustavo A. R. Silva
@ 2020-10-08 17:22 ` Alex Deucher
  2020-10-09  7:07 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2020-10-08 17:22 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: amd-gfx list, David Airlie, Felix Kuehling, LKML,
	Maling list - DRI developers, linux-hardening, Alex Deucher,
	Christian König

Applied.  Thanks!

Alex

On Thu, Oct 8, 2020 at 10:17 AM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> Make use of the new struct_size() helper instead of the offsetof() idiom.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 5da487b64a66..30192dce7775 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -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
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] drm/amdgpu: Use struct_size() helper in kmalloc()
  2020-10-08 14:23 [PATCH][next] drm/amdgpu: Use struct_size() helper in kmalloc() Gustavo A. R. Silva
  2020-10-08 17:22 ` Alex Deucher
@ 2020-10-09  7:07 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Christian König @ 2020-10-09  7:07 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Felix Kuehling, Alex Deucher, David Airlie,
	Daniel Vetter
  Cc: linux-hardening, dri-devel, amd-gfx, linux-kernel

Am 08.10.20 um 16:23 schrieb Gustavo A. R. Silva:
> Make use of the new struct_size() helper instead of the offsetof() idiom.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 5da487b64a66..30192dce7775 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -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;
>   

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-09  7:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 14:23 [PATCH][next] drm/amdgpu: Use struct_size() helper in kmalloc() Gustavo A. R. Silva
2020-10-08 17:22 ` Alex Deucher
2020-10-09  7:07 ` Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).