[PATCH] drm/amdgpu: Fix kcalloc over kzalloc in 'gmc_v9_0_init_mem_ranges'
Chen, Guchun
Guchun.Chen at amd.com
Fri Aug 18 09:48:54 UTC 2023
[Public]
Reviewed-by: Guchun Chen <guchun.chen at amd.com>
Regards,
Guchun
> -----Original Message-----
> From: SHANMUGAM, SRINIVASAN <SRINIVASAN.SHANMUGAM at amd.com>
> Sent: Friday, August 18, 2023 2:46 PM
> To: Koenig, Christian <Christian.Koenig at amd.com>; Deucher, Alexander
> <Alexander.Deucher at amd.com>; Chen, Guchun <Guchun.Chen at amd.com>
> Cc: amd-gfx at lists.freedesktop.org; SHANMUGAM, SRINIVASAN
> <SRINIVASAN.SHANMUGAM at amd.com>; Pan, Xinhui
> <Xinhui.Pan at amd.com>
> Subject: [PATCH] drm/amdgpu: Fix kcalloc over kzalloc in
> 'gmc_v9_0_init_mem_ranges'
>
> Replace kzalloc(n * sizeof(...), ...) with kcalloc(n, sizeof(...), ...) since kcalloc is
> the preferred API in case of allocating with multiply.
>
> Fixes the below:
>
> WARNING: Prefer kcalloc over kzalloc with multiply
>
> Cc: Guchun Chen <guchun.chen at amd.com>
> Cc: Christian König <christian.koenig at amd.com>
> Cc: Alex Deucher <alexander.deucher at amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan at amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> index f9a5a2c0573e..0673cda547bb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> @@ -1972,10 +1972,9 @@ static int gmc_v9_0_init_mem_ranges(struct
> amdgpu_device *adev) {
> bool valid;
>
> - adev->gmc.mem_partitions = kzalloc(
> - MAX_MEM_RANGES * sizeof(struct
> amdgpu_mem_partition_info),
> - GFP_KERNEL);
> -
> + adev->gmc.mem_partitions = kcalloc(MAX_MEM_RANGES,
> + sizeof(struct
> amdgpu_mem_partition_info),
> + GFP_KERNEL);
> if (!adev->gmc.mem_partitions)
> return -ENOMEM;
>
> --
> 2.25.1
More information about the amd-gfx
mailing list