summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Khatri <sunil.khatri@amd.com>2026-03-06 09:54:29 +0300
committerAlex Deucher <alexander.deucher@amd.com>2026-03-07 00:34:15 +0300
commita07930e4db4ceecb22f5ae63c97ed09c020844f8 (patch)
tree60fc56dfca1c13e0dcebb69ac6e6f4c4b3f446e1
parent28cacaace5cde8318b7da967b3955a73cc6de91a (diff)
downloadlinux-a07930e4db4ceecb22f5ae63c97ed09c020844f8.tar.xz
drm/amdgpu/userq: declutter the code with goto
Clean up the amdgpu_userq_create function clean up in failure condition using goto method. This avoid replication of cleanup for every failure condition. Signed-off-by: Sunil Khatri <sunil.khatri@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 049227fdb73a..4392a0fb6380 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -818,17 +818,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
amdgpu_userq_input_va_validate(adev, queue, args->in.rptr_va, AMDGPU_GPU_PAGE_SIZE) ||
amdgpu_userq_input_va_validate(adev, queue, args->in.wptr_va, AMDGPU_GPU_PAGE_SIZE)) {
r = -EINVAL;
- kfree(queue);
- goto unlock;
+ goto free_queue;
}
/* Convert relative doorbell offset into absolute doorbell index */
index = amdgpu_userq_get_doorbell_index(uq_mgr, &db_info, filp);
if (index == (uint64_t)-EINVAL) {
drm_file_err(uq_mgr->file, "Failed to get doorbell for queue\n");
- kfree(queue);
r = -EINVAL;
- goto unlock;
+ goto free_queue;
}
queue->doorbell_index = index;
@@ -836,15 +834,13 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
r = amdgpu_userq_fence_driver_alloc(adev, queue);
if (r) {
drm_file_err(uq_mgr->file, "Failed to alloc fence driver\n");
- goto unlock;
+ goto free_queue;
}
r = uq_funcs->mqd_create(queue, &args->in);
if (r) {
drm_file_err(uq_mgr->file, "Failed to create Queue\n");
- amdgpu_userq_fence_driver_free(queue);
- kfree(queue);
- goto unlock;
+ goto clean_fence_driver;
}
/* don't map the queue if scheduling is halted */
@@ -858,10 +854,8 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
r = amdgpu_userq_map_helper(queue);
if (r) {
drm_file_err(uq_mgr->file, "Failed to map Queue\n");
- uq_funcs->mqd_destroy(queue);
- amdgpu_userq_fence_driver_free(queue);
- kfree(queue);
- goto unlock;
+ down_read(&adev->reset_domain->sem);
+ goto clean_mqd;
}
}
@@ -870,18 +864,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
/* Wait for mode-1 reset to complete */
down_read(&adev->reset_domain->sem);
+
r = xa_alloc(&uq_mgr->userq_xa, &qid, queue,
XA_LIMIT(1, AMDGPU_MAX_USERQ_COUNT), GFP_KERNEL);
if (r) {
if (!skip_map_queue)
amdgpu_userq_unmap_helper(queue);
- uq_funcs->mqd_destroy(queue);
- amdgpu_userq_fence_driver_free(queue);
- kfree(queue);
r = -ENOMEM;
- up_read(&adev->reset_domain->sem);
- goto unlock;
+ goto clean_mqd;
}
r = xa_err(xa_store_irq(&adev->userq_doorbell_xa, index, queue, GFP_KERNEL));
@@ -890,11 +881,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
if (!skip_map_queue)
amdgpu_userq_unmap_helper(queue);
- uq_funcs->mqd_destroy(queue);
- amdgpu_userq_fence_driver_free(queue);
- kfree(queue);
- up_read(&adev->reset_domain->sem);
- goto unlock;
+ goto clean_mqd;
}
up_read(&adev->reset_domain->sem);
@@ -910,7 +897,16 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
args->out.queue_id = qid;
atomic_inc(&uq_mgr->userq_count[queue->queue_type]);
+ mutex_unlock(&uq_mgr->userq_mutex);
+ return 0;
+clean_mqd:
+ uq_funcs->mqd_destroy(queue);
+ up_read(&adev->reset_domain->sem);
+clean_fence_driver:
+ amdgpu_userq_fence_driver_free(queue);
+free_queue:
+ kfree(queue);
unlock:
mutex_unlock(&uq_mgr->userq_mutex);