drm/amdkfd: Fix kfd_process_device_init_vm error handling
authorjsg <jsg@openbsd.org>
Fri, 13 Jan 2023 01:38:35 +0000 (01:38 +0000)
committerjsg <jsg@openbsd.org>
Fri, 13 Jan 2023 01:38:35 +0000 (01:38 +0000)
From Philip Yang
9d74d1f52e16d8e07f7fbe52e96d6391418a2fe9 in linux-6.1.y/6.1.5
29d48b87db64b6697ddad007548e51d032081c59 in mainline linux

sys/dev/pci/drm/amd/amdkfd/kfd_process.c

index 951b636..9821fa9 100644 (file)
@@ -689,13 +689,13 @@ void kfd_process_destroy_wq(void)
 }
 
 static void kfd_process_free_gpuvm(struct kgd_mem *mem,
-                       struct kfd_process_device *pdd, void *kptr)
+                       struct kfd_process_device *pdd, void **kptr)
 {
        struct kfd_dev *dev = pdd->dev;
 
-       if (kptr) {
+       if (kptr && *kptr) {
                amdgpu_amdkfd_gpuvm_unmap_gtt_bo_from_kernel(mem);
-               kptr = NULL;
+               *kptr = NULL;
        }
 
        amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(dev->adev, mem, pdd->drm_priv);
@@ -795,7 +795,7 @@ static void kfd_process_device_destroy_ib_mem(struct kfd_process_device *pdd)
        if (!qpd->ib_kaddr || !qpd->ib_base)
                return;
 
-       kfd_process_free_gpuvm(qpd->ib_mem, pdd, qpd->ib_kaddr);
+       kfd_process_free_gpuvm(qpd->ib_mem, pdd, &qpd->ib_kaddr);
 }
 
 struct kfd_process *kfd_create_process(struct file *filep)
@@ -1277,7 +1277,7 @@ static void kfd_process_device_destroy_cwsr_dgpu(struct kfd_process_device *pdd)
        if (!dev->cwsr_enabled || !qpd->cwsr_kaddr || !qpd->cwsr_base)
                return;
 
-       kfd_process_free_gpuvm(qpd->cwsr_mem, pdd, qpd->cwsr_kaddr);
+       kfd_process_free_gpuvm(qpd->cwsr_mem, pdd, &qpd->cwsr_kaddr);
 }
 
 void kfd_process_set_trap_handler(struct qcm_process_device *qpd,
@@ -1598,8 +1598,8 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
        return 0;
 
 err_init_cwsr:
+       kfd_process_device_destroy_ib_mem(pdd);
 err_reserve_ib_mem:
-       kfd_process_device_free_bos(pdd);
        pdd->drm_priv = NULL;
 
        return ret;