]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA: Use ib_is_udata_in_empty() for places calling ib_is_udata_cleared()
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 12 May 2026 00:09:30 +0000 (21:09 -0300)
committerLeon Romanovsky <leon@kernel.org>
Mon, 18 May 2026 08:58:42 +0000 (04:58 -0400)
Convert the pattern:

  if (udata->inlen && !ib_is_udata_cleared(udata, 0, udata->inlen))

Using Coccinelle:

virtual patch
virtual context
virtual report

@@
expression udata;
@@
(
- udata->inlen && !ib_is_udata_cleared(udata, 0, udata->inlen)
+ !ib_is_udata_in_empty(udata)
|
- udata->inlen > 0 && !ib_is_udata_cleared(udata, 0, udata->inlen)
+ !ib_is_udata_in_empty(udata)
)

@@
expression udata;
@@
- udata && udata->inlen && !ib_is_udata_cleared(udata, 0, udata->inlen)
+ !ib_is_udata_in_empty(udata)

These cases are already checking for zeroed data that the kernel does
not understand.

Run another pass with AI to propagate the return code correctly and
remove redundant prints.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/efa/efa_verbs.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx4/qp.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/qp.c

index 7bd0838ebc99e414b05db079c81f3162eef9d783..3ad5d6e27b15903d28085bc38ba3d7c97bd2d444 100644 (file)
@@ -218,12 +218,9 @@ int efa_query_device(struct ib_device *ibdev,
        struct efa_dev *dev = to_edev(ibdev);
        int err;
 
-       if (udata && udata->inlen &&
-           !ib_is_udata_cleared(udata, 0, udata->inlen)) {
-               ibdev_dbg(ibdev,
-                         "Incompatible ABI params, udata not cleared\n");
-               return -EINVAL;
-       }
+       err = ib_is_udata_in_empty(udata);
+       if (err)
+               return err;
 
        dev_attr = &dev->dev_attr;
 
@@ -433,13 +430,9 @@ int efa_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
        struct efa_pd *pd = to_epd(ibpd);
        int err;
 
-       if (udata->inlen &&
-           !ib_is_udata_cleared(udata, 0, udata->inlen)) {
-               ibdev_dbg(&dev->ibdev,
-                         "Incompatible ABI params, udata not cleared\n");
-               err = -EINVAL;
+       err = ib_is_udata_in_empty(udata);
+       if (err)
                goto err_out;
-       }
 
        err = efa_com_alloc_pd(&dev->edev, &result);
        if (err)
@@ -982,12 +975,9 @@ int efa_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
        if (qp_attr_mask & ~IB_QP_ATTR_STANDARD_BITS)
                return -EOPNOTSUPP;
 
-       if (udata->inlen &&
-           !ib_is_udata_cleared(udata, 0, udata->inlen)) {
-               ibdev_dbg(&dev->ibdev,
-                         "Incompatible ABI params, udata not cleared\n");
-               return -EINVAL;
-       }
+       err = ib_is_udata_in_empty(udata);
+       if (err)
+               return err;
 
        cur_state = qp_attr_mask & IB_QP_CUR_STATE ? qp_attr->cur_qp_state :
                                                     qp->state;
@@ -1612,13 +1602,11 @@ static struct efa_mr *efa_alloc_mr(struct ib_pd *ibpd, int access_flags,
        struct efa_dev *dev = to_edev(ibpd->device);
        int supp_access_flags;
        struct efa_mr *mr;
+       int ret;
 
-       if (udata && udata->inlen &&
-           !ib_is_udata_cleared(udata, 0, udata->inlen)) {
-               ibdev_dbg(&dev->ibdev,
-                         "Incompatible ABI params, udata not cleared\n");
-               return ERR_PTR(-EINVAL);
-       }
+       ret = ib_is_udata_in_empty(udata);
+       if (ret)
+               return ERR_PTR(ret);
 
        supp_access_flags =
                IB_ACCESS_LOCAL_WRITE |
@@ -2082,12 +2070,9 @@ int efa_create_ah(struct ib_ah *ibah,
                goto err_out;
        }
 
-       if (udata->inlen &&
-           !ib_is_udata_cleared(udata, 0, udata->inlen)) {
-               ibdev_dbg(&dev->ibdev, "Incompatible ABI params\n");
-               err = -EINVAL;
+       err = ib_is_udata_in_empty(udata);
+       if (err)
                goto err_out;
-       }
 
        memcpy(params.dest_addr, ah_attr->grh.dgid.raw,
               sizeof(params.dest_addr));
index 464c9ab4251636202a708c1c9f73b17717be57ca..16e9ce8138cb30c879d73504f5cf9dad5aa92f0a 100644 (file)
@@ -1696,9 +1696,9 @@ static struct ib_flow *mlx4_ib_create_flow(struct ib_qp *qp,
            (flow_attr->type != IB_FLOW_ATTR_NORMAL))
                return ERR_PTR(-EOPNOTSUPP);
 
-       if (udata &&
-           udata->inlen && !ib_is_udata_cleared(udata, 0, udata->inlen))
-               return ERR_PTR(-EOPNOTSUPP);
+       err = ib_is_udata_in_empty(udata);
+       if (err)
+               return ERR_PTR(err);
 
        memset(type, 0, sizeof(type));
 
index 790be09d985a1a42642e27857d67f433f8318b60..aca8a985ce33cdc250f6c82801402fdebfa16bad 100644 (file)
@@ -4297,10 +4297,9 @@ int mlx4_ib_create_rwq_ind_table(struct ib_rwq_ind_table *rwq_ind_table,
        size_t min_resp_len;
        int i, err = 0;
 
-       if (udata->inlen > 0 &&
-           !ib_is_udata_cleared(udata, 0,
-                                udata->inlen))
-               return -EOPNOTSUPP;
+       err = ib_is_udata_in_empty(udata);
+       if (err)
+               return err;
 
        min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved);
        if (udata->outlen && udata->outlen < min_resp_len)
index 45f5fcd9adf06d5dd8591934d22d7ff4bb2a015d..01b21530e390b0d3b53491f5accb2970ad91341b 100644 (file)
@@ -965,8 +965,9 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
 
        resp.response_length = resp_len;
 
-       if (uhw && uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen))
-               return -EINVAL;
+       err = ib_is_udata_in_empty(uhw);
+       if (err)
+               return err;
 
        memset(props, 0, sizeof(*props));
        err = mlx5_query_system_image_guid(ibdev,
index 3048d2d273d742a3069ff38f2747feb66c45cef1..1a37209457ef5983568924929009ce06261b26a3 100644 (file)
@@ -5529,10 +5529,9 @@ int mlx5_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table,
        u32 *in;
        void *rqtc;
 
-       if (udata->inlen > 0 &&
-           !ib_is_udata_cleared(udata, 0,
-                                udata->inlen))
-               return -EOPNOTSUPP;
+       err = ib_is_udata_in_empty(udata);
+       if (err)
+               return err;
 
        if (init_attr->log_ind_tbl_size >
            MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)) {