Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/uverbs: Add an ib_uobject getter to ioctl() infrastructure

Previously, the user had to dig inside the attribute to get the uobject.
Add a helper function that correctly extract it (and do the required
checks) for him/her.

Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Michael J. Ruhl <michael.j.ruhl@intel.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Matan Barak and committed by
Leon Romanovsky
3efa3812 5f9bf63a

+25 -13
+12 -11
drivers/infiniband/core/uverbs_std_types_cq.c
··· 65 65 struct ib_cq_init_attr attr = {}; 66 66 struct ib_cq *cq; 67 67 struct ib_uverbs_completion_event_file *ev_file = NULL; 68 - const struct uverbs_attr *ev_file_attr; 69 68 struct ib_uobject *ev_file_uobj; 70 69 71 70 if (!(ib_dev->uverbs_cmd_mask & 1ULL << IB_USER_VERBS_CMD_CREATE_CQ)) ··· 86 87 UVERBS_ATTR_CREATE_CQ_FLAGS))) 87 88 return -EFAULT; 88 89 89 - ev_file_attr = uverbs_attr_get(attrs, UVERBS_ATTR_CREATE_CQ_COMP_CHANNEL); 90 - if (!IS_ERR(ev_file_attr)) { 91 - ev_file_uobj = ev_file_attr->obj_attr.uobject; 92 - 90 + ev_file_uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_CQ_COMP_CHANNEL); 91 + if (!IS_ERR(ev_file_uobj)) { 93 92 ev_file = container_of(ev_file_uobj, 94 93 struct ib_uverbs_completion_event_file, 95 94 uobj_file.uobj); ··· 99 102 goto err_event_file; 100 103 } 101 104 102 - obj = container_of(uverbs_attr_get(attrs, 103 - UVERBS_ATTR_CREATE_CQ_HANDLE)->obj_attr.uobject, 105 + obj = container_of(uverbs_attr_get_uobject(attrs, 106 + UVERBS_ATTR_CREATE_CQ_HANDLE), 104 107 typeof(*obj), uobject); 105 108 obj->uverbs_file = ucontext->ufile; 106 109 obj->comp_events_reported = 0; ··· 167 170 struct ib_uverbs_file *file, 168 171 struct uverbs_attr_bundle *attrs) 169 172 { 170 - struct ib_uverbs_destroy_cq_resp resp; 171 173 struct ib_uobject *uobj = 172 - uverbs_attr_get(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE)->obj_attr.uobject; 173 - struct ib_ucq_object *obj = container_of(uobj, struct ib_ucq_object, 174 - uobject); 174 + uverbs_attr_get_uobject(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE); 175 + struct ib_uverbs_destroy_cq_resp resp; 176 + struct ib_ucq_object *obj; 175 177 int ret; 178 + 179 + if (IS_ERR(uobj)) 180 + return PTR_ERR(uobj); 181 + 182 + obj = container_of(uobj, struct ib_ucq_object, uobject); 176 183 177 184 if (!(ib_dev->uverbs_cmd_mask & 1ULL << IB_USER_VERBS_CMD_DESTROY_CQ)) 178 185 return -EOPNOTSUPP;
+2 -2
drivers/infiniband/core/uverbs_std_types_flow_action.c
··· 320 320 return ret; 321 321 322 322 /* No need to check as this attribute is marked as MANDATORY */ 323 - uobj = uverbs_attr_get(attrs, UVERBS_ATTR_FLOW_ACTION_ESP_HANDLE)->obj_attr.uobject; 323 + uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_FLOW_ACTION_ESP_HANDLE); 324 324 action = ib_dev->create_flow_action_esp(ib_dev, &esp_attr.hdr, attrs); 325 325 if (IS_ERR(action)) 326 326 return PTR_ERR(action); ··· 350 350 if (ret) 351 351 return ret; 352 352 353 - uobj = uverbs_attr_get(attrs, UVERBS_ATTR_FLOW_ACTION_ESP_HANDLE)->obj_attr.uobject; 353 + uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_FLOW_ACTION_ESP_HANDLE); 354 354 action = uobj->object; 355 355 356 356 if (action->type != IB_FLOW_ACTION_ESP)
+11
include/rdma/uverbs_ioctl.h
··· 420 420 return uobj->object; 421 421 } 422 422 423 + static inline struct ib_uobject *uverbs_attr_get_uobject(const struct uverbs_attr_bundle *attrs_bundle, 424 + u16 idx) 425 + { 426 + const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 427 + 428 + if (IS_ERR(attr)) 429 + return ERR_CAST(attr); 430 + 431 + return attr->obj_attr.uobject; 432 + } 433 + 423 434 static inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle, 424 435 size_t idx, const void *from, size_t size) 425 436 {