drm/amdkfd: err_pin_bo path leaks kfd_bo_list
authorPhilip Yang <Philip.Yang@amd.com>
Mon, 29 Nov 2021 20:21:50 +0000 (15:21 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 1 Dec 2021 21:16:00 +0000 (16:16 -0500)
Refactor userptr and pin_bo path to make it less confusing, move
err_pin_bo label up to remove mem from process_info kfd_bo_list.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

index 5df89a2..b849078 100644 (file)
@@ -1559,13 +1559,8 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
                ret = init_user_pages(*mem, user_addr);
                if (ret)
                        goto allocate_init_user_pages_failed;
-       }
-
-       if (offset)
-               *offset = amdgpu_bo_mmap_offset(bo);
-
-       if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL |
-                       KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) {
+       } else  if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL |
+                               KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) {
                ret = amdgpu_amdkfd_gpuvm_pin_bo(bo, AMDGPU_GEM_DOMAIN_GTT);
                if (ret) {
                        pr_err("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n");
@@ -1575,11 +1570,14 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
                bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
        }
 
+       if (offset)
+               *offset = amdgpu_bo_mmap_offset(bo);
+
        return 0;
 
 allocate_init_user_pages_failed:
-       remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info);
 err_pin_bo:
+       remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info);
        drm_vma_node_revoke(&gobj->vma_node, drm_priv);
 err_node_allow:
        /* Don't unreserve system mem limit twice */