summaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/core/rdma_core.c
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@mellanox.com>2018-07-04 11:32:06 +0300
committerJason Gunthorpe <jgg@mellanox.com>2018-07-09 11:26:17 -0600
commitc33e73af2183fb9fcd993e37abcdecc058b22d91 (patch)
treef85591d06f6362c845a38f8473be7916ee238822 /drivers/infiniband/core/rdma_core.c
parent422e3d37ed7ea8b421208a44913c420055334976 (diff)
downloadlinux-c33e73af2183fb9fcd993e37abcdecc058b22d91.tar.bz2
IB/uverbs: Add a uobj_perform_destroy helper
This consolidates a bunch of repeated code patterns into a helper. Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Diffstat (limited to 'drivers/infiniband/core/rdma_core.c')
-rw-r--r--drivers/infiniband/core/rdma_core.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index c67bcdda5760..38d3929f6e65 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -128,6 +128,28 @@ static int uverbs_try_lock_object(struct ib_uobject *uobj, bool exclusive)
return atomic_cmpxchg(&uobj->usecnt, 0, -1) == 0 ? 0 : -EBUSY;
}
+/*
+ * Does both rdma_lookup_get_uobject() and rdma_remove_commit_uobject(), then
+ * returns success_res on success (negative errno on failure). For use by
+ * callers that do not need the uobj.
+ */
+int __uobj_perform_destroy(const struct uverbs_obj_type *type, int id,
+ struct ib_uverbs_file *ufile, int success_res)
+{
+ struct ib_uobject *uobj;
+ int ret;
+
+ uobj = rdma_lookup_get_uobject(type, ufile->ucontext, id, true);
+ if (IS_ERR(uobj))
+ return PTR_ERR(uobj);
+
+ ret = rdma_remove_commit_uobject(uobj);
+ if (ret)
+ return ret;
+
+ return success_res;
+}
+
static struct ib_uobject *alloc_uobj(struct ib_ucontext *context,
const struct uverbs_obj_type *type)
{