Commit 2c96eb7d authored by Jason Gunthorpe's avatar Jason Gunthorpe

IB/uverbs: Always propagate errors from rdma_alloc_commit_uobject()

The ioctl framework already does this correctly, but the write path did
not. This is trivially fixed by simply using a standard pattern to return
uobj_alloc_commit() as the last statement in every function.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent e951747a
...@@ -532,9 +532,10 @@ static void alloc_commit_fd_uobject(struct ib_uobject *uobj) ...@@ -532,9 +532,10 @@ static void alloc_commit_fd_uobject(struct ib_uobject *uobj)
/* /*
* In all cases rdma_alloc_commit_uobject() consumes the kref to uobj and the * In all cases rdma_alloc_commit_uobject() consumes the kref to uobj and the
* caller can no longer assume uobj is valid. * caller can no longer assume uobj is valid. If this function fails it
* destroys the uboject, including the attached HW object.
*/ */
int rdma_alloc_commit_uobject(struct ib_uobject *uobj) int __must_check rdma_alloc_commit_uobject(struct ib_uobject *uobj)
{ {
struct ib_uverbs_file *ufile = uobj->ufile; struct ib_uverbs_file *ufile = uobj->ufile;
......
...@@ -372,9 +372,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, ...@@ -372,9 +372,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
goto err_copy; goto err_copy;
} }
uobj_alloc_commit(uobj); return uobj_alloc_commit(uobj, in_len);
return in_len;
err_copy: err_copy:
ib_dealloc_pd(pd); ib_dealloc_pd(pd);
...@@ -579,9 +577,7 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, ...@@ -579,9 +577,7 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
mutex_unlock(&file->device->xrcd_tree_mutex); mutex_unlock(&file->device->xrcd_tree_mutex);
uobj_alloc_commit(&obj->uobject); return uobj_alloc_commit(&obj->uobject, in_len);
return in_len;
err_copy: err_copy:
if (inode) { if (inode) {
...@@ -723,9 +719,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, ...@@ -723,9 +719,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
uobj_put_obj_read(pd); uobj_put_obj_read(pd);
uobj_alloc_commit(uobj); return uobj_alloc_commit(uobj, in_len);
return in_len;
err_copy: err_copy:
ib_dereg_mr(mr); ib_dereg_mr(mr);
...@@ -901,9 +895,7 @@ ssize_t ib_uverbs_alloc_mw(struct ib_uverbs_file *file, ...@@ -901,9 +895,7 @@ ssize_t ib_uverbs_alloc_mw(struct ib_uverbs_file *file,
} }
uobj_put_obj_read(pd); uobj_put_obj_read(pd);
uobj_alloc_commit(uobj); return uobj_alloc_commit(uobj, in_len);
return in_len;
err_copy: err_copy:
uverbs_dealloc_mw(mw); uverbs_dealloc_mw(mw);
...@@ -959,8 +951,7 @@ ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file, ...@@ -959,8 +951,7 @@ ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file,
return -EFAULT; return -EFAULT;
} }
uobj_alloc_commit(uobj); return uobj_alloc_commit(uobj, in_len);
return in_len;
} }
static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file,
...@@ -1041,7 +1032,9 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, ...@@ -1041,7 +1032,9 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file,
if (ret) if (ret)
goto err_cb; goto err_cb;
uobj_alloc_commit(&obj->uobject); ret = uobj_alloc_commit(&obj->uobject, 0);
if (ret)
return ERR_PTR(ret);
return obj; return obj;
err_cb: err_cb:
...@@ -1596,9 +1589,7 @@ static int create_qp(struct ib_uverbs_file *file, ...@@ -1596,9 +1589,7 @@ static int create_qp(struct ib_uverbs_file *file,
if (ind_tbl) if (ind_tbl)
uobj_put_obj_read(ind_tbl); uobj_put_obj_read(ind_tbl);
uobj_alloc_commit(&obj->uevent.uobject); return uobj_alloc_commit(&obj->uevent.uobject, 0);
return 0;
err_cb: err_cb:
ib_destroy_qp(qp); ib_destroy_qp(qp);
...@@ -1801,10 +1792,7 @@ ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file, ...@@ -1801,10 +1792,7 @@ ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file,
qp->uobject = &obj->uevent.uobject; qp->uobject = &obj->uevent.uobject;
uobj_put_read(xrcd_uobj); uobj_put_read(xrcd_uobj);
return uobj_alloc_commit(&obj->uevent.uobject, in_len);
uobj_alloc_commit(&obj->uevent.uobject);
return in_len;
err_destroy: err_destroy:
ib_destroy_qp(qp); ib_destroy_qp(qp);
...@@ -2607,9 +2595,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, ...@@ -2607,9 +2595,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
} }
uobj_put_obj_read(pd); uobj_put_obj_read(pd);
uobj_alloc_commit(uobj); return uobj_alloc_commit(uobj, in_len);
return in_len;
err_copy: err_copy:
rdma_destroy_ah(ah); rdma_destroy_ah(ah);
...@@ -3155,8 +3141,7 @@ int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file, ...@@ -3155,8 +3141,7 @@ int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file,
uobj_put_obj_read(pd); uobj_put_obj_read(pd);
uobj_put_obj_read(cq); uobj_put_obj_read(cq);
uobj_alloc_commit(&obj->uevent.uobject); return uobj_alloc_commit(&obj->uevent.uobject, 0);
return 0;
err_copy: err_copy:
ib_destroy_wq(wq); ib_destroy_wq(wq);
...@@ -3403,8 +3388,7 @@ int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file, ...@@ -3403,8 +3388,7 @@ int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file,
for (j = 0; j < num_read_wqs; j++) for (j = 0; j < num_read_wqs; j++)
uobj_put_obj_read(wqs[j]); uobj_put_obj_read(wqs[j]);
uobj_alloc_commit(uobj); return uobj_alloc_commit(uobj, 0);
return 0;
err_copy: err_copy:
ib_destroy_rwq_ind_table(rwq_ind_tbl); ib_destroy_rwq_ind_table(rwq_ind_tbl);
...@@ -3605,11 +3589,10 @@ int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file, ...@@ -3605,11 +3589,10 @@ int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file,
goto err_copy; goto err_copy;
uobj_put_obj_read(qp); uobj_put_obj_read(qp);
uobj_alloc_commit(uobj);
kfree(flow_attr); kfree(flow_attr);
if (cmd.flow_attr.num_of_specs) if (cmd.flow_attr.num_of_specs)
kfree(kern_flow_attr); kfree(kern_flow_attr);
return 0; return uobj_alloc_commit(uobj, 0);
err_copy: err_copy:
if (!qp->device->destroy_flow(flow_id)) if (!qp->device->destroy_flow(flow_id))
atomic_dec(&qp->usecnt); atomic_dec(&qp->usecnt);
...@@ -3761,9 +3744,7 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, ...@@ -3761,9 +3744,7 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
uobj_put_obj_read(attr.ext.cq); uobj_put_obj_read(attr.ext.cq);
uobj_put_obj_read(pd); uobj_put_obj_read(pd);
uobj_alloc_commit(&obj->uevent.uobject); return uobj_alloc_commit(&obj->uevent.uobject, 0);
return 0;
err_copy: err_copy:
ib_destroy_srq(srq); ib_destroy_srq(srq);
......
...@@ -102,9 +102,14 @@ static inline int __must_check uobj_remove_commit(struct ib_uobject *uobj) ...@@ -102,9 +102,14 @@ static inline int __must_check uobj_remove_commit(struct ib_uobject *uobj)
return rdma_remove_commit_uobject(uobj); return rdma_remove_commit_uobject(uobj);
} }
static inline void uobj_alloc_commit(struct ib_uobject *uobj) static inline int __must_check uobj_alloc_commit(struct ib_uobject *uobj,
int success_res)
{ {
rdma_alloc_commit_uobject(uobj); int ret = rdma_alloc_commit_uobject(uobj);
if (ret)
return ret;
return success_res;
} }
static inline void uobj_alloc_abort(struct ib_uobject *uobj) static inline void uobj_alloc_abort(struct ib_uobject *uobj)
......
...@@ -127,7 +127,7 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_obj_type *type, ...@@ -127,7 +127,7 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_obj_type *type,
struct ib_uverbs_file *ufile); struct ib_uverbs_file *ufile);
void rdma_alloc_abort_uobject(struct ib_uobject *uobj); void rdma_alloc_abort_uobject(struct ib_uobject *uobj);
int __must_check rdma_remove_commit_uobject(struct ib_uobject *uobj); int __must_check rdma_remove_commit_uobject(struct ib_uobject *uobj);
int rdma_alloc_commit_uobject(struct ib_uobject *uobj); int __must_check rdma_alloc_commit_uobject(struct ib_uobject *uobj);
int rdma_explicit_destroy(struct ib_uobject *uobject); int rdma_explicit_destroy(struct ib_uobject *uobject);
struct uverbs_obj_fd_type { struct uverbs_obj_fd_type {
......
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