]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/hns: Use ib_copy_validate_udata_in()
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 25 Mar 2026 21:26:56 +0000 (18:26 -0300)
committerLeon Romanovsky <leonro@nvidia.com>
Tue, 31 Mar 2026 07:18:16 +0000 (03:18 -0400)
Follow the last struct member from the commit when the struct was
added to the kernel.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
drivers/infiniband/hw/hns/hns_roce_cq.c
drivers/infiniband/hw/hns/hns_roce_main.c
drivers/infiniband/hw/hns/hns_roce_qp.c
drivers/infiniband/hw/hns/hns_roce_srq.c

index 857a913326cd88d8a3341a3dded3d38d6062db4e..621568e114054b5e38714167a1dd421f09f73acf 100644 (file)
@@ -350,20 +350,6 @@ static int verify_cq_create_attr(struct hns_roce_dev *hr_dev,
        return 0;
 }
 
-static int get_cq_ucmd(struct hns_roce_cq *hr_cq, struct ib_udata *udata,
-                      struct hns_roce_ib_create_cq *ucmd)
-{
-       struct ib_device *ibdev = hr_cq->ib_cq.device;
-       int ret;
-
-       ret = ib_copy_from_udata(ucmd, udata, min(udata->inlen, sizeof(*ucmd)));
-       if (ret) {
-               ibdev_err(ibdev, "failed to copy CQ udata, ret = %d.\n", ret);
-               return ret;
-       }
-
-       return 0;
-}
 
 static void set_cq_param(struct hns_roce_cq *hr_cq, u32 cq_entries, int vector,
                         struct hns_roce_ib_create_cq *ucmd)
@@ -428,7 +414,7 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr,
                goto err_out;
 
        if (udata) {
-               ret = get_cq_ucmd(hr_cq, udata, &ucmd);
+               ret = ib_copy_validate_udata_in(udata, ucmd, db_addr);
                if (ret)
                        goto err_out;
        }
index 1148d732f94fbf6de01268016cddbb5482959c76..ec6fb3f1177941bffbae3dae969127886dc2b732 100644 (file)
@@ -36,6 +36,7 @@
 #include <rdma/ib_smi.h>
 #include <rdma/ib_user_verbs.h>
 #include <rdma/ib_cache.h>
+#include <rdma/uverbs_ioctl.h>
 #include "hns_roce_common.h"
 #include "hns_roce_device.h"
 #include "hns_roce_hem.h"
@@ -433,8 +434,7 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
        resp.qp_tab_size = hr_dev->caps.num_qps;
        resp.srq_tab_size = hr_dev->caps.num_srqs;
 
-       ret = ib_copy_from_udata(&ucmd, udata,
-                                min(udata->inlen, sizeof(ucmd)));
+       ret = ib_copy_validate_udata_in(udata, ucmd, reserved);
        if (ret)
                goto error_out;
 
index 6a2dff4bd2d0fcb2afb5c03bfd115421e43eaace..3d6eb22cbcd940efde8f7d0d36d03699cfb81d15 100644 (file)
@@ -1130,13 +1130,9 @@ static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
        }
 
        if (udata) {
-               ret = ib_copy_from_udata(ucmd, udata,
-                                        min(udata->inlen, sizeof(*ucmd)));
-               if (ret) {
-                       ibdev_err(ibdev,
-                                 "failed to copy QP ucmd, ret = %d\n", ret);
+               ret = ib_copy_validate_udata_in(udata, *ucmd, reserved);
+               if (ret)
                        return ret;
-               }
 
                uctx = rdma_udata_to_drv_context(udata, struct hns_roce_ucontext,
                                                 ibucontext);
index 8a6efb6b9c9ebaf44a802ea7af7f025b7bac0de6..b37a76587aa868d6d57cc5d42322e0bc839e13ce 100644 (file)
@@ -346,14 +346,9 @@ static int alloc_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
        int ret;
 
        if (udata) {
-               ret = ib_copy_from_udata(&ucmd, udata,
-                                        min(udata->inlen, sizeof(ucmd)));
-               if (ret) {
-                       ibdev_err(&hr_dev->ib_dev,
-                                 "failed to copy SRQ udata, ret = %d.\n",
-                                 ret);
+               ret = ib_copy_validate_udata_in(udata, ucmd, que_addr);
+               if (ret)
                        return ret;
-               }
        }
 
        ret = alloc_srq_idx(hr_dev, srq, udata, ucmd.que_addr);
@@ -387,20 +382,6 @@ static void free_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
        free_srq_idx(hr_dev, srq);
 }
 
-static int get_srq_ucmd(struct hns_roce_srq *srq, struct ib_udata *udata,
-                       struct hns_roce_ib_create_srq *ucmd)
-{
-       struct ib_device *ibdev = srq->ibsrq.device;
-       int ret;
-
-       ret = ib_copy_from_udata(ucmd, udata, min(udata->inlen, sizeof(*ucmd)));
-       if (ret) {
-               ibdev_err(ibdev, "failed to copy SRQ udata, ret = %d.\n", ret);
-               return ret;
-       }
-
-       return 0;
-}
 
 static void free_srq_db(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
                        struct ib_udata *udata)
@@ -430,7 +411,7 @@ static int alloc_srq_db(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
        int ret;
 
        if (udata) {
-               ret = get_srq_ucmd(srq, udata, &ucmd);
+               ret = ib_copy_validate_udata_in(udata, ucmd, que_addr);
                if (ret)
                        return ret;