Skip to content

Commit 062ea90

Browse files
superm1alexdeucher
authored andcommitted
drm/amd: Fix NULL pointer dereference in device cleanup
When GPU initialization fails due to an unsupported HW block IP blocks may have a NULL version pointer. During cleanup in amdgpu_device_fini_hw, the code calls amdgpu_device_set_pg_state and amdgpu_device_set_cg_state which iterate over all IP blocks and access adev->ip_blocks[i].version without NULL checks, leading to a kernel NULL pointer dereference. Add NULL checks for adev->ip_blocks[i].version in both amdgpu_device_set_cg_state and amdgpu_device_set_pg_state to prevent dereferencing NULL pointers during GPU teardown when initialization has failed. Fixes: 39fc2bc ("drm/amdgpu: Protect GPU register accesses in powergated state in some paths") Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit b7ac774) Cc: stable@vger.kernel.org
1 parent 9d4837a commit 062ea90

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,6 +3247,8 @@ int amdgpu_device_set_cg_state(struct amdgpu_device *adev,
32473247
i = state == AMD_CG_STATE_GATE ? j : adev->num_ip_blocks - j - 1;
32483248
if (!adev->ip_blocks[i].status.late_initialized)
32493249
continue;
3250+
if (!adev->ip_blocks[i].version)
3251+
continue;
32503252
/* skip CG for GFX, SDMA on S0ix */
32513253
if (adev->in_s0ix &&
32523254
(adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GFX ||
@@ -3286,6 +3288,8 @@ int amdgpu_device_set_pg_state(struct amdgpu_device *adev,
32863288
i = state == AMD_PG_STATE_GATE ? j : adev->num_ip_blocks - j - 1;
32873289
if (!adev->ip_blocks[i].status.late_initialized)
32883290
continue;
3291+
if (!adev->ip_blocks[i].version)
3292+
continue;
32893293
/* skip PG for GFX, SDMA on S0ix */
32903294
if (adev->in_s0ix &&
32913295
(adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GFX ||

0 commit comments

Comments
 (0)