[PATCH] drm/amdgpu: kref_put() may not require a lock.
From: Yejune Deng
Date: Wed Dec 23 2020 - 03:05:02 EST
kref_put() can be outside of mutex_lock(),and use amdgpu_ctx_put()
instead of kref_put().
Signed-off-by: Yejune Deng <yejune.deng@xxxxxxxxx>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 0350205..af26ec2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -282,6 +282,15 @@ static void amdgpu_ctx_do_release(struct kref *ref)
amdgpu_ctx_fini(ref);
}
+int amdgpu_ctx_put(struct amdgpu_ctx *ctx)
+{
+ if (ctx == NULL)
+ return -EINVAL;
+
+ kref_put(&ctx->refcount, amdgpu_ctx_do_release);
+ return 0;
+}
+
static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
{
struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;
@@ -289,10 +298,9 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
mutex_lock(&mgr->lock);
ctx = idr_remove(&mgr->ctx_handles, id);
- if (ctx)
- kref_put(&ctx->refcount, amdgpu_ctx_do_release);
mutex_unlock(&mgr->lock);
- return ctx ? 0 : -EINVAL;
+
+ return amdgpu_ctx_put(ctx);
}
static int amdgpu_ctx_query(struct amdgpu_device *adev,
@@ -439,15 +447,6 @@ struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id)
return ctx;
}
-int amdgpu_ctx_put(struct amdgpu_ctx *ctx)
-{
- if (ctx == NULL)
- return -EINVAL;
-
- kref_put(&ctx->refcount, amdgpu_ctx_do_release);
- return 0;
-}
-
void amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
struct drm_sched_entity *entity,
struct dma_fence *fence, uint64_t *handle)
--
1.9.1