amdgpu: Adjust kmalloc_array calls for new -Walloc-size
authorSam James <sam@gentoo.org>
Sun, 5 Nov 2023 16:06:50 +0000 (16:06 +0000)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 17 Nov 2023 14:29:54 +0000 (09:29 -0500)
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>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c

index 625db444df1cb60ddff16397f0714ef4238d91ad..0ba15dcbe4e131ae6bc4ee23db6caa83282c476a 100644 (file)
@@ -200,7 +200,7 @@ int kgd_arcturus_hqd_sdma_dump(struct amdgpu_device *adev,
 #undef HQD_N_REGS
 #define HQD_N_REGS (19+6+7+10)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
index f6598b9e4faa35b7fc51b9def3637e7e273189b1..a5c7259cf2a3e858dd753fe782a13c529ddef536 100644 (file)
@@ -141,7 +141,7 @@ static int kgd_gfx_v9_4_3_hqd_sdma_dump(struct amdgpu_device *adev,
                (*dump)[i++][1] = RREG32(addr);         \
        } while (0)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
index 6bf448ab3dffc1a9a40dd1658e19ae6cb8328fb4..ca4a6b82817f5349c8434c9aa0c1c89658853c30 100644 (file)
@@ -214,7 +214,7 @@ static int kgd_hqd_dump(struct amdgpu_device *adev,
                (*dump)[i++][1] = RREG32(addr);         \
        } while (0)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
@@ -301,7 +301,7 @@ static int kgd_hqd_sdma_dump(struct amdgpu_device *adev,
 #undef HQD_N_REGS
 #define HQD_N_REGS (19+4)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
index cd06e4a6d1da4825e353752406c156337fa76577..0f3e2944edd7e9d4aca62d48bcfa00ab7c6b0a16 100644 (file)
@@ -238,7 +238,7 @@ static int kgd_hqd_dump(struct amdgpu_device *adev,
                (*dump)[i++][1] = RREG32(addr);         \
        } while (0)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
@@ -324,7 +324,7 @@ static int kgd_hqd_sdma_dump(struct amdgpu_device *adev,
 #undef HQD_N_REGS
 #define HQD_N_REGS (19+4+2+3+7)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
index 00fbc0f44c929bee0e34af62d96b5ff8c36d6ec6..5a35a8ca89222bafc8f9c3ea12d5ee134b37ba52 100644 (file)
@@ -363,7 +363,7 @@ int kgd_gfx_v9_hqd_dump(struct amdgpu_device *adev,
                (*dump)[i++][1] = RREG32(addr);         \
        } while (0)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
@@ -460,7 +460,7 @@ static int kgd_hqd_sdma_dump(struct amdgpu_device *adev,
 #undef HQD_N_REGS
 #define HQD_N_REGS (19+6+7+10)
 
-       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS, sizeof(**dump), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;