Skip to content

Commit d186e51

Browse files
mhaimovskiThomas Hellström
authored andcommitted
drm/xe/vm: bugfix in xe_vm_create_ioctl
Fix xe_vm_create_ioctl routine not freeing the vm-id allocated to it when the function fails. Fixes: dd08ebf ("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 f6bf042) Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
1 parent c0e2508 commit d186e51

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,22 +1855,18 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
18551855
mutex_lock(&xef->vm.lock);
18561856
err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
18571857
mutex_unlock(&xef->vm.lock);
1858-
if (err) {
1859-
xe_vm_close_and_put(vm);
1860-
return err;
1861-
}
1858+
if (err)
1859+
goto err_close_and_put;
18621860

18631861
if (xe->info.has_asid) {
18641862
mutex_lock(&xe->usm.lock);
18651863
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
18661864
XA_LIMIT(1, XE_MAX_ASID - 1),
18671865
&xe->usm.next_asid, GFP_KERNEL);
18681866
mutex_unlock(&xe->usm.lock);
1869-
if (err < 0) {
1870-
xe_vm_close_and_put(vm);
1871-
return err;
1872-
}
1873-
err = 0;
1867+
if (err < 0)
1868+
goto err_free_id;
1869+
18741870
vm->usm.asid = asid;
18751871
}
18761872

@@ -1888,6 +1884,15 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
18881884
#endif
18891885

18901886
return 0;
1887+
1888+
err_free_id:
1889+
mutex_lock(&xef->vm.lock);
1890+
xa_erase(&xef->vm.xa, id);
1891+
mutex_unlock(&xef->vm.lock);
1892+
err_close_and_put:
1893+
xe_vm_close_and_put(vm);
1894+
1895+
return err;
18911896
}
18921897

18931898
int xe_vm_destroy_ioctl(struct drm_device *dev, void *data,

0 commit comments

Comments
 (0)