[PATCH for-next v2 2/3] IB/verbs: add helper function rdma_udata_to_drv_context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Helper function to get driver's context out of ib_udata wrapped
in uverbs_attr_bundle for uer 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 94b6e1dd4dab..fb4d078d6db3 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -4264,4 +4264,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.
+ *
+ * NOTE: This macro return NULL for kernel objects and valid driver context for
+ * user objects.
+ */
+#define rdma_udata_to_drv_context(udata, drv_dev_struct, member)               \
+	({ struct ib_ucontext *_ibctx = rdma_get_ucontext(udata);              \
+	   IS_ERR(_ibctx) ? NULL :                                             \
+	       container_of(_ibctx, drv_dev_struct, member);                   \
+	})
+
 #endif /* IB_VERBS_H */
-- 
2.17.2




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux