Skip to content

Commit d5c8f2f

Browse files
jgunthorperleon
authored andcommitted
RDMA/hns: Use ib_copy_validate_udata_in()
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>
1 parent 0453bf0 commit d5c8f2f

4 files changed

Lines changed: 8 additions & 45 deletions

File tree

drivers/infiniband/hw/hns/hns_roce_cq.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,6 @@ static int verify_cq_create_attr(struct hns_roce_dev *hr_dev,
350350
return 0;
351351
}
352352

353-
static int get_cq_ucmd(struct hns_roce_cq *hr_cq, struct ib_udata *udata,
354-
struct hns_roce_ib_create_cq *ucmd)
355-
{
356-
struct ib_device *ibdev = hr_cq->ib_cq.device;
357-
int ret;
358-
359-
ret = ib_copy_from_udata(ucmd, udata, min(udata->inlen, sizeof(*ucmd)));
360-
if (ret) {
361-
ibdev_err(ibdev, "failed to copy CQ udata, ret = %d.\n", ret);
362-
return ret;
363-
}
364-
365-
return 0;
366-
}
367353

368354
static void set_cq_param(struct hns_roce_cq *hr_cq, u32 cq_entries, int vector,
369355
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,
428414
goto err_out;
429415

430416
if (udata) {
431-
ret = get_cq_ucmd(hr_cq, udata, &ucmd);
417+
ret = ib_copy_validate_udata_in(udata, ucmd, db_addr);
432418
if (ret)
433419
goto err_out;
434420
}

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <rdma/ib_smi.h>
3737
#include <rdma/ib_user_verbs.h>
3838
#include <rdma/ib_cache.h>
39+
#include <rdma/uverbs_ioctl.h>
3940
#include "hns_roce_common.h"
4041
#include "hns_roce_device.h"
4142
#include "hns_roce_hem.h"
@@ -433,8 +434,7 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
433434
resp.qp_tab_size = hr_dev->caps.num_qps;
434435
resp.srq_tab_size = hr_dev->caps.num_srqs;
435436

436-
ret = ib_copy_from_udata(&ucmd, udata,
437-
min(udata->inlen, sizeof(ucmd)));
437+
ret = ib_copy_validate_udata_in(udata, ucmd, reserved);
438438
if (ret)
439439
goto error_out;
440440

drivers/infiniband/hw/hns/hns_roce_qp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,13 +1130,9 @@ static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
11301130
}
11311131

11321132
if (udata) {
1133-
ret = ib_copy_from_udata(ucmd, udata,
1134-
min(udata->inlen, sizeof(*ucmd)));
1135-
if (ret) {
1136-
ibdev_err(ibdev,
1137-
"failed to copy QP ucmd, ret = %d\n", ret);
1133+
ret = ib_copy_validate_udata_in(udata, *ucmd, reserved);
1134+
if (ret)
11381135
return ret;
1139-
}
11401136

11411137
uctx = rdma_udata_to_drv_context(udata, struct hns_roce_ucontext,
11421138
ibucontext);

drivers/infiniband/hw/hns/hns_roce_srq.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,9 @@ static int alloc_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
346346
int ret;
347347

348348
if (udata) {
349-
ret = ib_copy_from_udata(&ucmd, udata,
350-
min(udata->inlen, sizeof(ucmd)));
351-
if (ret) {
352-
ibdev_err(&hr_dev->ib_dev,
353-
"failed to copy SRQ udata, ret = %d.\n",
354-
ret);
349+
ret = ib_copy_validate_udata_in(udata, ucmd, que_addr);
350+
if (ret)
355351
return ret;
356-
}
357352
}
358353

359354
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)
387382
free_srq_idx(hr_dev, srq);
388383
}
389384

390-
static int get_srq_ucmd(struct hns_roce_srq *srq, struct ib_udata *udata,
391-
struct hns_roce_ib_create_srq *ucmd)
392-
{
393-
struct ib_device *ibdev = srq->ibsrq.device;
394-
int ret;
395-
396-
ret = ib_copy_from_udata(ucmd, udata, min(udata->inlen, sizeof(*ucmd)));
397-
if (ret) {
398-
ibdev_err(ibdev, "failed to copy SRQ udata, ret = %d.\n", ret);
399-
return ret;
400-
}
401-
402-
return 0;
403-
}
404385

405386
static void free_srq_db(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
406387
struct ib_udata *udata)
@@ -430,7 +411,7 @@ static int alloc_srq_db(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
430411
int ret;
431412

432413
if (udata) {
433-
ret = get_srq_ucmd(srq, udata, &ucmd);
414+
ret = ib_copy_validate_udata_in(udata, ucmd, que_addr);
434415
if (ret)
435416
return ret;
436417

0 commit comments

Comments
 (0)