> > 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. > > Signed-off-by: Jason Gunthorpe <[email protected]>
Reviewed-by: Long Li <[email protected]> > --- > drivers/infiniband/hw/mana/cq.c | 9 ++------- > drivers/infiniband/hw/mlx5/cq.c > | 10 +++------- > 2 files changed, 5 insertions(+), 14 deletions(-) > > diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c > index b2749f971cd0af..3f932ef6e5fff6 100644 > --- a/drivers/infiniband/hw/mana/cq.c > +++ b/drivers/infiniband/hw/mana/cq.c > @@ -27,14 +27,9 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct > ib_cq_init_attr *attr, > is_rnic_cq = mana_ib_is_rnic(mdev); > > if (udata) { > - if (udata->inlen < offsetof(struct mana_ib_create_cq, flags)) > - return -EINVAL; > - > - err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), > udata->inlen)); > - if (err) { > - ibdev_dbg(ibdev, "Failed to copy from udata for create > cq, %d\n", err); > + err = ib_copy_validate_udata_in(udata, ucmd, buf_addr); > + if (err) > return err; > - } > > if ((!is_rnic_cq && attr->cqe > mdev->adapter_caps.max_qp_wr) > || > attr->cqe > U32_MAX / COMP_ENTRY_SIZE) { diff --git > a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c index > 43a7b5ca49dcc9..643b3b7d387834 100644 > --- a/drivers/infiniband/hw/mlx5/cq.c > +++ b/drivers/infiniband/hw/mlx5/cq.c > @@ -723,7 +723,6 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct > ib_udata *udata, > struct mlx5_ib_create_cq ucmd = {}; > unsigned long page_size; > unsigned int page_offset_quantized; > - size_t ucmdlen; > __be64 *pas; > int ncont; > void *cqc; > @@ -731,12 +730,9 @@ static int create_cq_user(struct mlx5_ib_dev *dev, > struct ib_udata *udata, > struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context( > udata, struct mlx5_ib_ucontext, ibucontext); > > - ucmdlen = min(udata->inlen, sizeof(ucmd)); > - if (ucmdlen < offsetof(struct mlx5_ib_create_cq, flags)) > - return -EINVAL; > - > - if (ib_copy_from_udata(&ucmd, udata, ucmdlen)) > - return -EFAULT; > + err = ib_copy_validate_udata_in(udata, ucmd, cqe_comp_res_format); > + if (err) > + return err; > > if ((ucmd.flags & ~(MLX5_IB_CREATE_CQ_FLAGS_CQE_128B_PAD | > MLX5_IB_CREATE_CQ_FLAGS_UAR_PAGE_INDEX | > -- > 2.43.0
