]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/infiniband/core/uverbs_std_types_cq.c
RDMA/core: Use READ_ONCE for ib_ufile.async_file
[linux.git] / drivers / infiniband / core / uverbs_std_types_cq.c
index 07ea4e3c45663a5fef7d889e986ddd3918a0efe4..da4110a0eea2c5511bf9bbee125b461df49f12f5 100644 (file)
@@ -41,7 +41,7 @@ static int uverbs_free_cq(struct ib_uobject *uobject,
        struct ib_cq *cq = uobject->object;
        struct ib_uverbs_event_queue *ev_queue = cq->cq_context;
        struct ib_ucq_object *ucq =
-               container_of(uobject, struct ib_ucq_object, uobject);
+               container_of(uobject, struct ib_ucq_object, uevent.uobject);
        int ret;
 
        ret = ib_destroy_cq_user(cq, &attrs->driver_udata);
@@ -49,7 +49,6 @@ static int uverbs_free_cq(struct ib_uobject *uobject,
                return ret;
 
        ib_uverbs_release_ucq(
-               attrs->ufile,
                ev_queue ? container_of(ev_queue,
                                        struct ib_uverbs_completion_event_file,
                                        ev_queue) :
@@ -63,7 +62,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
 {
        struct ib_ucq_object *obj = container_of(
                uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_CQ_HANDLE),
-               typeof(*obj), uobject);
+               typeof(*obj), uevent.uobject);
        struct ib_device *ib_dev = attrs->context->device;
        int ret;
        u64 user_handle;
@@ -106,26 +105,29 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
                goto err_event_file;
        }
 
-       obj->comp_events_reported  = 0;
-       obj->async_events_reported = 0;
        INIT_LIST_HEAD(&obj->comp_list);
-       INIT_LIST_HEAD(&obj->async_list);
+       INIT_LIST_HEAD(&obj->uevent.event_list);
 
-       cq = ib_dev->ops.create_cq(ib_dev, &attr, &attrs->driver_udata);
-       if (IS_ERR(cq)) {
-               ret = PTR_ERR(cq);
+       cq = rdma_zalloc_drv_obj(ib_dev, ib_cq);
+       if (!cq) {
+               ret = -ENOMEM;
                goto err_event_file;
        }
 
        cq->device        = ib_dev;
-       cq->uobject       = &obj->uobject;
+       cq->uobject       = obj;
        cq->comp_handler  = ib_uverbs_comp_handler;
        cq->event_handler = ib_uverbs_cq_event_handler;
        cq->cq_context    = ev_file ? &ev_file->ev_queue : NULL;
-       obj->uobject.object = cq;
-       obj->uobject.user_handle = user_handle;
        atomic_set(&cq->usecnt, 0);
        cq->res.type = RDMA_RESTRACK_CQ;
+
+       ret = ib_dev->ops.create_cq(cq, &attr, &attrs->driver_udata);
+       if (ret)
+               goto err_free;
+
+       obj->uevent.uobject.object = cq;
+       obj->uevent.uobject.user_handle = user_handle;
        rdma_restrack_uadd(&cq->res);
 
        ret = uverbs_copy_to(attrs, UVERBS_ATTR_CREATE_CQ_RESP_CQE, &cq->cqe,
@@ -136,7 +138,9 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
        return 0;
 err_cq:
        ib_destroy_cq_user(cq, uverbs_get_cleared_udata(attrs));
-
+       cq = NULL;
+err_free:
+       kfree(cq);
 err_event_file:
        if (ev_file)
                uverbs_uobject_put(ev_file_uobj);
@@ -175,10 +179,10 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(
        struct ib_uobject *uobj =
                uverbs_attr_get_uobject(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE);
        struct ib_ucq_object *obj =
-               container_of(uobj, struct ib_ucq_object, uobject);
+               container_of(uobj, struct ib_ucq_object, uevent.uobject);
        struct ib_uverbs_destroy_cq_resp resp = {
                .comp_events_reported = obj->comp_events_reported,
-               .async_events_reported = obj->async_events_reported
+               .async_events_reported = obj->uevent.events_reported
        };
 
        return uverbs_copy_to(attrs, UVERBS_ATTR_DESTROY_CQ_RESP, &resp,