]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA: Consolidate patterns with offsetof() to ib_copy_validate_udata_in()
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 25 Mar 2026 21:26:48 +0000 (18:26 -0300)
committerLeon Romanovsky <leonro@nvidia.com>
Tue, 31 Mar 2026 07:11:01 +0000 (03:11 -0400)
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>
drivers/infiniband/hw/mana/cq.c
drivers/infiniband/hw/mlx5/cq.c

index b2749f971cd0afe5ff70eecd5753012b02692c31..3f932ef6e5fff6f3b3be9e18a9325ecc3440ded5 100644 (file)
@@ -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) {
index 806b4f25af709b0fe5a9bb6101b4ebf58e140e27..bed28ceab812bc734b4d507704519c65ea596244 100644 (file)
@@ -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 |