drm/xe/vm: bugfix in xe_vm_create_ioctl
authorMoti Haimovski <mhaimovski@habana.ai>
Mon, 22 Jan 2024 10:24:24 +0000 (12:24 +0200)
committerThomas Hellström <thomas.hellstrom@linux.intel.com>
Wed, 24 Jan 2024 10:13:41 +0000 (11:13 +0100)
Fix xe_vm_create_ioctl routine not freeing the vm-id allocated to it
when the function fails.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Signed-off-by: Moti Haimovski <mhaimovski@habana.ai>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Tomer Tayar <ttayar@habana.ai>
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240122102424.4008095-1-mhaimovski@habana.ai
(cherry picked from commit f6bf0424cadc27d7cf6a049d2db960e4b52fa513)
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
drivers/gpu/drm/xe/xe_vm.c

index 10b6995fbf294690a36234dc3c36bf741245b7a9..53833ab81424ceeca8edd95e15a2c6a34e681f6c 100644 (file)
@@ -1855,10 +1855,8 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
        mutex_lock(&xef->vm.lock);
        err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
        mutex_unlock(&xef->vm.lock);
-       if (err) {
-               xe_vm_close_and_put(vm);
-               return err;
-       }
+       if (err)
+               goto err_close_and_put;
 
        if (xe->info.has_asid) {
                mutex_lock(&xe->usm.lock);
@@ -1866,11 +1864,9 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
                                      XA_LIMIT(1, XE_MAX_ASID - 1),
                                      &xe->usm.next_asid, GFP_KERNEL);
                mutex_unlock(&xe->usm.lock);
-               if (err < 0) {
-                       xe_vm_close_and_put(vm);
-                       return err;
-               }
-               err = 0;
+               if (err < 0)
+                       goto err_free_id;
+
                vm->usm.asid = asid;
        }
 
@@ -1888,6 +1884,15 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
 #endif
 
        return 0;
+
+err_free_id:
+       mutex_lock(&xef->vm.lock);
+       xa_erase(&xef->vm.xa, id);
+       mutex_unlock(&xef->vm.lock);
+err_close_and_put:
+       xe_vm_close_and_put(vm);
+
+       return err;
 }
 
 int xe_vm_destroy_ioctl(struct drm_device *dev, void *data,