Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

amdgpu: Adjust kmalloc_array calls for new -Walloc-size

GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
on various files in drivers/gpu/drm/amd/amdgpu like:
```
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]
```

This is because each HQD_N_REGS is actually a uint32_t[2]. Move the * 2 to
the size argument so GCC sees we're allocating enough.

Originally did 'sizeof(uint32_t) * 2' for the size but a friend suggested
'sizeof(**dump)' better communicates the intent.

Link: https://lore.kernel.org/all/87wmuwo7i3.fsf@gentoo.org/
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Sam James and committed by
Alex Deucher
b5a52d2a fbbcb3f2

+8 -8
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c
··· 200 200 #undef HQD_N_REGS 201 201 #define HQD_N_REGS (19+6+7+10) 202 202 203 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 203 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 204 204 if (*dump == NULL) 205 205 return -ENOMEM; 206 206
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c
··· 141 141 (*dump)[i++][1] = RREG32(addr); \ 142 142 } while (0) 143 143 144 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 144 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 145 145 if (*dump == NULL) 146 146 return -ENOMEM; 147 147
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
··· 214 214 (*dump)[i++][1] = RREG32(addr); \ 215 215 } while (0) 216 216 217 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 217 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 218 218 if (*dump == NULL) 219 219 return -ENOMEM; 220 220 ··· 301 301 #undef HQD_N_REGS 302 302 #define HQD_N_REGS (19+4) 303 303 304 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 304 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 305 305 if (*dump == NULL) 306 306 return -ENOMEM; 307 307
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
··· 238 238 (*dump)[i++][1] = RREG32(addr); \ 239 239 } while (0) 240 240 241 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 241 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 242 242 if (*dump == NULL) 243 243 return -ENOMEM; 244 244 ··· 324 324 #undef HQD_N_REGS 325 325 #define HQD_N_REGS (19+4+2+3+7) 326 326 327 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 327 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 328 328 if (*dump == NULL) 329 329 return -ENOMEM; 330 330
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
··· 363 363 (*dump)[i++][1] = RREG32(addr); \ 364 364 } while (0) 365 365 366 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 366 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 367 367 if (*dump == NULL) 368 368 return -ENOMEM; 369 369 ··· 460 460 #undef HQD_N_REGS 461 461 #define HQD_N_REGS (19+6+7+10) 462 462 463 - *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL); 463 + *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL); 464 464 if (*dump == NULL) 465 465 return -ENOMEM; 466 466