Commit 167b95ec authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/ucma: Use refcount_t for the ctx->ref

Don't use an atomic as a refcount.

Link: https://lore.kernel.org/r/20200218191657.GA29724@ziepe.caReviewed-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent b72bfc96
...@@ -85,7 +85,7 @@ struct ucma_file { ...@@ -85,7 +85,7 @@ struct ucma_file {
struct ucma_context { struct ucma_context {
u32 id; u32 id;
struct completion comp; struct completion comp;
atomic_t ref; refcount_t ref;
int events_reported; int events_reported;
int backlog; int backlog;
...@@ -152,7 +152,7 @@ static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id) ...@@ -152,7 +152,7 @@ static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id)
if (ctx->closing) if (ctx->closing)
ctx = ERR_PTR(-EIO); ctx = ERR_PTR(-EIO);
else else
atomic_inc(&ctx->ref); refcount_inc(&ctx->ref);
} }
xa_unlock(&ctx_table); xa_unlock(&ctx_table);
return ctx; return ctx;
...@@ -160,7 +160,7 @@ static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id) ...@@ -160,7 +160,7 @@ static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id)
static void ucma_put_ctx(struct ucma_context *ctx) static void ucma_put_ctx(struct ucma_context *ctx)
{ {
if (atomic_dec_and_test(&ctx->ref)) if (refcount_dec_and_test(&ctx->ref))
complete(&ctx->comp); complete(&ctx->comp);
} }
...@@ -212,7 +212,7 @@ static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file) ...@@ -212,7 +212,7 @@ static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
return NULL; return NULL;
INIT_WORK(&ctx->close_work, ucma_close_id); INIT_WORK(&ctx->close_work, ucma_close_id);
atomic_set(&ctx->ref, 1); refcount_set(&ctx->ref, 1);
init_completion(&ctx->comp); init_completion(&ctx->comp);
INIT_LIST_HEAD(&ctx->mc_list); INIT_LIST_HEAD(&ctx->mc_list);
ctx->file = file; ctx->file = file;
...@@ -1502,7 +1502,7 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file, ...@@ -1502,7 +1502,7 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file,
mc = ERR_PTR(-ENOENT); mc = ERR_PTR(-ENOENT);
else if (mc->ctx->file != file) else if (mc->ctx->file != file)
mc = ERR_PTR(-EINVAL); mc = ERR_PTR(-EINVAL);
else if (!atomic_inc_not_zero(&mc->ctx->ref)) else if (!refcount_inc_not_zero(&mc->ctx->ref))
mc = ERR_PTR(-ENXIO); mc = ERR_PTR(-ENXIO);
else else
__xa_erase(&multicast_table, mc->id); __xa_erase(&multicast_table, mc->id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment