Helper function to get driver's context out of ib_udata wrapped in uverbs_attr_bundle for uesr objects or NULL for kernel objects. Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx> --- include/rdma/ib_verbs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 600b3319f443..065640b415bd 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -4262,4 +4262,18 @@ static inline struct ib_device *rdma_device_to_ibdev(struct device *device) */ #define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member) \ container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member) + +/** + * rdma_udata_to_drv_context - Helper macro to get the driver's context out of + * ib_udata which is embadded in uverbs_attr_bundle. + * + * If udata is not NULL this cannot fail. Otherwise a NULL udata will result + * in a NULL ucontext pointer. Callers can rely on !NULL ucontext to show the + * op is being called as part of a user system call. + */ +#define rdma_udata_to_drv_context(udata, drv_dev_struct, member) \ + (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \ + driver_udata)->context, drv_dev_struct, member) : \ + (drv_dev_struct *)NULL) + #endif /* IB_VERBS_H */ -- 2.17.2