amdgpu_amdkfd_gfx* triggers new -Walloc-size warnings in GCC 14

From: Sam James
Date: Sun Nov 05 2023 - 04:49:01 EST


GCC 14 introduces a new -Walloc-size warning (https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-alloc-size)
which triggers on the following amdgpu files:
"""
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c: In function ‘kgd_hqd_dump’:
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c:241:15: error: allocation of insufficient size ‘4’ for type ‘uint32_t[2]’ {aka ‘unsigned int[2
]’} with size ‘8’ [-Werror=alloc-size[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Walloc-size]]
241 | *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
| ^
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c: In function ‘kgd_hqd_sdma_dump’:
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c:327:15: error: allocation of insufficient size ‘4’ for type ‘uint32_t[2]’ {aka ‘unsigned int[2
]’} with size ‘8’ [-Werror=alloc-size[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Walloc-size]]
327 | *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
| ^
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c: In function ‘kgd_arcturus_hqd_sdma_dump’:
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c:203:15: error: allocation of insufficient size ‘4’ for type ‘uint32_t[2]’ {aka ‘unsigned int
[2]’} with size ‘8’ [-Werror=alloc-size[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Walloc-size]]
203 | *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
| ^
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c: In function ‘kgd_gfx_v9_4_3_hqd_sdma_dump’:
/var/tmp/portage/sys-kernel/gentoo-kernel-6.5.10/work/linux-6.5/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c:142:15: error: allocation of insufficient size ‘4’ for type ‘uint32_t[2]’ {aka ‘unsigned int
[2]’} with size ‘8’ [-Werror=alloc-size[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Walloc-size]]
142 | *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
| ^
"""

$ gcc-14 --version
gcc-14 (Gentoo Hardened 14.0.0 p, commit
2b02f083e67e97f8187d3ec023c3d281f49232c0) 14.0.0 20231104 (experimental)
8d22ac6a18cf542cd541c06b2a7df8fdd293946d
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

thanks,
sam