>-----Original Message----- >From: linux-rdma-owner@xxxxxxxxxxxxxxx [mailto:linux-rdma- >owner@xxxxxxxxxxxxxxx] On Behalf Of Leon Romanovsky >Sent: Thursday, May 3, 2018 9:37 AM >To: Doug Ledford <dledford@xxxxxxxxxx>; Jason Gunthorpe ><jgg@xxxxxxxxxxxx> >Cc: Leon Romanovsky <leonro@xxxxxxxxxxxx>; RDMA mailing list <linux- >rdma@xxxxxxxxxxxxxxx>; Matan Barak <matanb@xxxxxxxxxxxx>; Yishai >Hadas <yishaih@xxxxxxxxxxxx> >Subject: [PATCH rdma-next 04/21] IB/uverbs: Get a specification from a >method by specifying the index > >From: Matan Barak <matanb@xxxxxxxxxxxx> > >In order to have strong validations, we have to get the specification. >Add a helper function to get the specification from a method. > >Signed-off-by: Matan Barak <matanb@xxxxxxxxxxxx> >Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> >--- > drivers/infiniband/core/rdma_core.c | 11 ----------- > drivers/infiniband/core/rdma_core.h | 1 - > include/rdma/uverbs_ioctl.h | 29 +++++++++++++++++++++++++++++ > 3 files changed, 29 insertions(+), 12 deletions(-) > >diff --git a/drivers/infiniband/core/rdma_core.c >b/drivers/infiniband/core/rdma_core.c >index 8035a0a7564c..167c3de2120d 100644 >--- a/drivers/infiniband/core/rdma_core.c >+++ b/drivers/infiniband/core/rdma_core.c >@@ -41,17 +41,6 @@ > #include "core_priv.h" > #include "rdma_core.h" > >-int uverbs_ns_idx(u16 *id, unsigned int ns_count) >-{ >- int ret = (*id & UVERBS_ID_NS_MASK) >> UVERBS_ID_NS_SHIFT; >- >- if (ret >= ns_count) >- return -EINVAL; >- >- *id &= ~UVERBS_ID_NS_MASK; >- return ret; >-} >- > const struct uverbs_object_spec *uverbs_get_object(const struct ib_device >*ibdev, > uint16_t object) > { >diff --git a/drivers/infiniband/core/rdma_core.h >b/drivers/infiniband/core/rdma_core.h >index 1efcf93238dd..1c3790640072 100644 >--- a/drivers/infiniband/core/rdma_core.h >+++ b/drivers/infiniband/core/rdma_core.h >@@ -43,7 +43,6 @@ > #include <rdma/ib_verbs.h> > #include <linux/mutex.h> > >-int uverbs_ns_idx(u16 *id, unsigned int ns_count); > const struct uverbs_object_spec *uverbs_get_object(const struct ib_device >*ibdev, > uint16_t object); > const struct uverbs_method_spec *uverbs_get_method(const struct >uverbs_object_spec *object, >diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h >index 4a4201d997a7..86b3a780bbef 100644 >--- a/include/rdma/uverbs_ioctl.h >+++ b/include/rdma/uverbs_ioctl.h >@@ -366,6 +366,35 @@ struct uverbs_attr_bundle { > struct uverbs_attr_bundle_hash hash[]; > }; > >+static inline int uverbs_ns_idx(u16 *id, unsigned int ns_count) >+{ >+ int ret = (*id & UVERBS_ID_NS_MASK) >> UVERBS_ID_NS_SHIFT; >+ >+ if (ret >= ns_count) >+ return -EINVAL; >+ >+ *id &= ~UVERBS_ID_NS_MASK; >+ return ret; >+} >+ >+static inline const struct uverbs_attr_spec * >+uverbs_get_spec(const struct uverbs_method_spec *method, u16 idx) Is it expected that this function is going to be called from outside of the rdma core icotl parsing area? If not, would it be better placed in an header file in the core directory? Mike >+{ >+ u16 id = idx; >+ int ns = uverbs_ns_idx(&id, method->num_buckets); >+ const struct uverbs_attr_spec_hash *curr_spec_bucket; >+ >+ if (ns < 0) >+ return ERR_PTR(ns); >+ >+ curr_spec_bucket = method->attr_buckets[ns]; >+ >+ if (id >= curr_spec_bucket->num_attrs) >+ return ERR_PTR(-ENOENT); >+ >+ return &curr_spec_bucket->attrs[id]; >+} >+ > static inline bool uverbs_attr_is_valid_in_hash(const struct >uverbs_attr_bundle_hash *attrs_hash, > unsigned int idx) > { >-- >2.14.3 > >-- >To unsubscribe from this list: send the line "unsubscribe linux-rdma" in >the body of a message to majordomo@xxxxxxxxxxxxxxx >More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html