]> git.hungrycats.org Git - linux/commitdiff
drm/amdgpu/mes: Add NULL check for mes_hung_db_array allocation
authorGeoffrey McRae <geoffrey.mcrae@amd.com>
Sun, 28 Jun 2026 06:17:01 +0000 (16:17 +1000)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 8 Jul 2026 18:20:29 +0000 (14:20 -0400)
kcalloc but does not check for failure. If the allocation fails, the
pointer remains NULL but the function returns success. Subsequent code
using this buffer will dereference a NULL pointer, causing a kernel
oops. Add a check to return -ENOMEM if the allocation fails.

Signed-off-by: Geoffrey McRae <geoffrey.mcrae@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c

index 6c0dde3786e34bb2268cd48b065b842687806707..261ddc19c840b54e9af19e91a60e9824f8ab8f2c 100644 (file)
@@ -250,11 +250,16 @@ int amdgpu_mes_init(struct amdgpu_device *adev)
                                goto error_doorbell;
                        }
                }
-       }
 
-       adev->gfx.mec.mes_hung_db_array =
-               kcalloc(amdgpu_mes_get_hung_queue_db_array_size(adev),
-                       sizeof(u32), GFP_KERNEL);
+               adev->gfx.mec.mes_hung_db_array =
+                       kcalloc(amdgpu_mes_get_hung_queue_db_array_size(adev),
+                               sizeof(u32), GFP_KERNEL);
+
+               if (!adev->gfx.mec.mes_hung_db_array) {
+                       r = -ENOMEM;
+                       goto error_doorbell;
+               }
+       }
 
        return 0;