before kfd_dev_unmap_mapping_range check ptr to avoid null pointer
 from failed or incomplete kfd node init.

Signed-off-by: Yiqing Yao <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 09feb45584bab..7256ec1290bcd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -330,11 +330,16 @@ void amdgpu_amdkfd_clear_kfd_mapping(struct amdgpu_device 
*adev)
        struct kfd_dev *kfd = adev->kfd.dev;
        unsigned int i;
 
-       if (!kfd)
+       /* kfd->num_nodes is set before kfd->nodes[] is populated, so a failed
+        * or incomplete kgd2kfd_device_init() leaves NULL node pointers behind
+        */
+       if (!kfd || !adev->kfd.init_complete)
                return;
 
        for (i = 0; i < kfd->num_nodes; i++) {
                struct kfd_node *node = kfd->nodes[i];
+               if (!node)
+                       continue;
 
                kfd_dev_unmap_mapping_range(KFD_MMAP_TYPE_DOORBELL |
                                            KFD_MMAP_GPU_ID(node->id),
-- 
2.34.1

Reply via email to