Skip to content

Commit 8d7573b

Browse files
jgunthorperleon
authored andcommitted
RDMA: Consolidate patterns with offsetof() to ib_copy_validate_udata_in()
Similar to the prior patch, these patterns are open coding an offsetofend(). The use of offsetof() targets the prior field as the last field in the struct. Reviewed-by: Long Li <longli@microsoft.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
1 parent ae63828 commit 8d7573b

2 files changed

Lines changed: 5 additions & 14 deletions

File tree

drivers/infiniband/hw/mana/cq.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
2727
is_rnic_cq = mana_ib_is_rnic(mdev);
2828

2929
if (udata) {
30-
if (udata->inlen < offsetof(struct mana_ib_create_cq, flags))
31-
return -EINVAL;
32-
33-
err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen));
34-
if (err) {
35-
ibdev_dbg(ibdev, "Failed to copy from udata for create cq, %d\n", err);
30+
err = ib_copy_validate_udata_in(udata, ucmd, buf_addr);
31+
if (err)
3632
return err;
37-
}
3833

3934
if ((!is_rnic_cq && attr->cqe > mdev->adapter_caps.max_qp_wr) ||
4035
attr->cqe > U32_MAX / COMP_ENTRY_SIZE) {

drivers/infiniband/hw/mlx5/cq.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -723,20 +723,16 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata,
723723
struct mlx5_ib_create_cq ucmd = {};
724724
unsigned long page_size;
725725
unsigned int page_offset_quantized;
726-
size_t ucmdlen;
727726
__be64 *pas;
728727
int ncont;
729728
void *cqc;
730729
int err;
731730
struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context(
732731
udata, struct mlx5_ib_ucontext, ibucontext);
733732

734-
ucmdlen = min(udata->inlen, sizeof(ucmd));
735-
if (ucmdlen < offsetof(struct mlx5_ib_create_cq, flags))
736-
return -EINVAL;
737-
738-
if (ib_copy_from_udata(&ucmd, udata, ucmdlen))
739-
return -EFAULT;
733+
err = ib_copy_validate_udata_in(udata, ucmd, cqe_comp_res_format);
734+
if (err)
735+
return err;
740736

741737
if ((ucmd.flags & ~(MLX5_IB_CREATE_CQ_FLAGS_CQE_128B_PAD |
742738
MLX5_IB_CREATE_CQ_FLAGS_UAR_PAGE_INDEX |

0 commit comments

Comments
 (0)