Skip to content

Commit 0453bf0

Browse files
jgunthorperleon
authored andcommitted
RDMA/mlx4: Use ib_copy_validate_udata_in() for QP
Move the validation of the udata to the same function that copies it. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
1 parent f899787 commit 0453bf0

1 file changed

Lines changed: 3 additions & 22 deletions

File tree

  • drivers/infiniband/hw/mlx4

drivers/infiniband/hw/mlx4/qp.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,6 @@ static int create_rq(struct ib_pd *pd, struct ib_qp_init_attr *init_attr,
854854
unsigned long flags;
855855
int range_size;
856856
struct mlx4_ib_create_wq wq;
857-
size_t copy_len;
858857
int shift;
859858
int n;
860859

@@ -867,12 +866,9 @@ static int create_rq(struct ib_pd *pd, struct ib_qp_init_attr *init_attr,
867866

868867
qp->state = IB_QPS_RESET;
869868

870-
copy_len = min(sizeof(struct mlx4_ib_create_wq), udata->inlen);
871-
872-
if (ib_copy_from_udata(&wq, udata, copy_len)) {
873-
err = -EFAULT;
869+
err = ib_copy_validate_udata_in(udata, wq, comp_mask);
870+
if (err)
874871
goto err;
875-
}
876872

877873
if (wq.comp_mask || wq.reserved[0] || wq.reserved[1] ||
878874
wq.reserved[2]) {
@@ -4112,26 +4108,11 @@ struct ib_wq *mlx4_ib_create_wq(struct ib_pd *pd,
41124108
struct mlx4_dev *dev = to_mdev(pd->device)->dev;
41134109
struct ib_qp_init_attr ib_qp_init_attr = {};
41144110
struct mlx4_ib_qp *qp;
4115-
struct mlx4_ib_create_wq ucmd;
4116-
int err, required_cmd_sz;
4111+
int err;
41174112

41184113
if (!udata)
41194114
return ERR_PTR(-EINVAL);
41204115

4121-
required_cmd_sz = offsetof(typeof(ucmd), comp_mask) +
4122-
sizeof(ucmd.comp_mask);
4123-
if (udata->inlen < required_cmd_sz) {
4124-
pr_debug("invalid inlen\n");
4125-
return ERR_PTR(-EINVAL);
4126-
}
4127-
4128-
if (udata->inlen > sizeof(ucmd) &&
4129-
!ib_is_udata_cleared(udata, sizeof(ucmd),
4130-
udata->inlen - sizeof(ucmd))) {
4131-
pr_debug("inlen is not supported\n");
4132-
return ERR_PTR(-EOPNOTSUPP);
4133-
}
4134-
41354116
if (udata->outlen)
41364117
return ERR_PTR(-EOPNOTSUPP);
41374118

0 commit comments

Comments
 (0)