aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
diff options
context:
space:
mode:
authorMatthew Wilcox <mawilcox@microsoft.com>2016-12-22 13:30:22 -0500
committerMatthew Wilcox <mawilcox@microsoft.com>2017-02-13 21:44:03 -0500
commitd3e709e63e97e5f3f129b639991cfe266da60bae (patch)
tree78647f4029b9e83087fefa19144a689f6909f8d2 /drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
parent8ac04868315c6ffcb2c5a5ad9cd5cec61cad3576 (diff)
idr: Return the deleted entry from idr_remove
It is a relatively common idiom (8 instances) to first look up an IDR entry, and then remove it from the tree if it is found, possibly doing further operations upon the entry afterwards. If we change idr_remove() to return the removed object, all of these users can save themselves a walk of the IDR tree. Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 400c66ba4c6b..cf0500671353 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -135,15 +135,11 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
135 struct amdgpu_ctx *ctx; 135 struct amdgpu_ctx *ctx;
136 136
137 mutex_lock(&mgr->lock); 137 mutex_lock(&mgr->lock);
138 ctx = idr_find(&mgr->ctx_handles, id); 138 ctx = idr_remove(&mgr->ctx_handles, id);
139 if (ctx) { 139 if (ctx)
140 idr_remove(&mgr->ctx_handles, id);
141 kref_put(&ctx->refcount, amdgpu_ctx_do_release); 140 kref_put(&ctx->refcount, amdgpu_ctx_do_release);
142 mutex_unlock(&mgr->lock);
143 return 0;
144 }
145 mutex_unlock(&mgr->lock); 141 mutex_unlock(&mgr->lock);
146 return -EINVAL; 142 return ctx ? 0 : -EINVAL;
147} 143}
148 144
149static int amdgpu_ctx_query(struct amdgpu_device *adev, 145static int amdgpu_ctx_query(struct amdgpu_device *adev,