diff options
author | Moni Shoua <monis@mellanox.com> | 2018-12-11 12:37:51 +0100 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2018-12-18 23:19:45 +0100 |
commit | cbfdd442c43eab8c62bf2ea5127511cd39e9046d (patch) | |
tree | bb71aec3b5960f8ab4ad74b1a77c1819b8ddc7dc /include/rdma | |
parent | RDMA/uverbs: Add an ioctl method to destroy an object (diff) | |
download | linux-cbfdd442c43eab8c62bf2ea5127511cd39e9046d.tar.xz linux-cbfdd442c43eab8c62bf2ea5127511cd39e9046d.zip |
IB/uverbs: Add helper to get array size from ptr attribute
When the parser of an ioctl command has the knowledge that a ptr attribute
in a bundle represents an array of structures, it is useful for it to know
the number of elements in the array. This is done by dividing the
attribute length with the element size.
Signed-off-by: Moni Shoua <monis@mellanox.com>
Reviewed-by: Guy Levi <guyle@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'include/rdma')
-rw-r--r-- | include/rdma/uverbs_ioctl.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index 839a857aa329..bf07cd6336d3 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -719,6 +719,28 @@ uverbs_attr_get_len(const struct uverbs_attr_bundle *attrs_bundle, u16 idx) return attr->ptr_attr.len; } +/* + * uverbs_attr_ptr_get_array_size() - Get array size pointer by a ptr + * attribute. + * @attrs: The attribute bundle + * @idx: The ID of the attribute + * @elem_size: The size of the element in the array + */ +static inline int +uverbs_attr_ptr_get_array_size(struct uverbs_attr_bundle *attrs, u16 idx, + size_t elem_size) +{ + int size = uverbs_attr_get_len(attrs, idx); + + if (size < 0) + return size; + + if (size % elem_size) + return -EINVAL; + + return size / elem_size; +} + /** * uverbs_attr_get_uobjs_arr() - Provides array's properties for attribute for * UVERBS_ATTR_TYPE_IDRS_ARRAY. |