drm/amdgpu: Fix null pointer dereference to bo
authorMa Jun <Jun.Ma2@amd.com>
Sat, 11 May 2024 08:08:06 +0000 (16:08 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 17 May 2024 21:09:47 +0000 (17:09 -0400)
Check bo before using it

Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

index 7d99fcc..34e751b 100644 (file)
@@ -497,9 +497,8 @@ static void gmc_v12_0_get_vm_pte(struct amdgpu_device *adev,
                                 uint64_t *flags)
 {
        struct amdgpu_bo *bo = mapping->bo_va->base.bo;
-       struct amdgpu_device *bo_adev = amdgpu_ttm_adev(bo->tbo.bdev);
-       bool coherent = bo->flags & AMDGPU_GEM_CREATE_COHERENT;
-       bool is_system = bo->tbo.resource->mem_type == TTM_PL_SYSTEM;
+       struct amdgpu_device *bo_adev;
+       bool coherent, is_system;
 
 
        *flags &= ~AMDGPU_PTE_EXECUTABLE;
@@ -515,13 +514,20 @@ static void gmc_v12_0_get_vm_pte(struct amdgpu_device *adev,
                *flags &= ~AMDGPU_PTE_VALID;
        }
 
-       if (bo && bo->flags & (AMDGPU_GEM_CREATE_COHERENT |
+       if (!bo)
+               return;
+
+       if (bo->flags & (AMDGPU_GEM_CREATE_COHERENT |
                               AMDGPU_GEM_CREATE_UNCACHED))
                *flags = (*flags & ~AMDGPU_PTE_MTYPE_GFX12_MASK) |
                         AMDGPU_PTE_MTYPE_GFX12(MTYPE_UC);
 
+       bo_adev = amdgpu_ttm_adev(bo->tbo.bdev);
+       coherent = bo->flags & AMDGPU_GEM_CREATE_COHERENT;
+       is_system = bo->tbo.resource->mem_type == TTM_PL_SYSTEM;
+
        /* WA for HW bug */
-       if ((bo && is_system) || ((bo_adev != adev) && coherent))
+       if (is_system || ((bo_adev != adev) && coherent))
                *flags |= AMDGPU_PTE_MTYPE_GFX12(MTYPE_NC);
 
 }