From: Jason Gunthorpe Date: Tue, 12 May 2026 00:09:33 +0000 (-0300) Subject: RDMA: Convert drivers using sizeof() to ib_respond_udata() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5189936049e91f4fd54b47f147232cde6f7ec7cc;p=thirdparty%2Fkernel%2Flinux.git RDMA: Convert drivers using sizeof() to ib_respond_udata() Convert the pattern: ib_copy_to_udata(udata, &resp, sizeof(resp)); Using Coccinelle: @@ identifier resp; expression udata; @@ - ib_copy_to_udata(udata, &resp, sizeof(resp)) + ib_respond_udata(udata, resp) Run another pass with AI to propagate the return code correctly and remove redundant prints. Signed-off-by: Jason Gunthorpe Signed-off-by: Leon Romanovsky --- diff --git a/drivers/infiniband/hw/cxgb4/provider.c b/drivers/infiniband/hw/cxgb4/provider.c index 616019ac1da50..a119e8793aef4 100644 --- a/drivers/infiniband/hw/cxgb4/provider.c +++ b/drivers/infiniband/hw/cxgb4/provider.c @@ -52,6 +52,7 @@ #include #include #include +#include #include "iw_cxgb4.h" @@ -209,8 +210,9 @@ static int c4iw_allocate_pd(struct ib_pd *pd, struct ib_udata *udata) { struct c4iw_pd *php = to_c4iw_pd(pd); struct ib_device *ibdev = pd->device; - u32 pdid; struct c4iw_dev *rhp; + u32 pdid; + int ret; pr_debug("ibdev %p\n", ibdev); rhp = (struct c4iw_dev *) ibdev; @@ -223,9 +225,10 @@ static int c4iw_allocate_pd(struct ib_pd *pd, struct ib_udata *udata) if (udata) { struct c4iw_alloc_pd_resp uresp = {.pdid = php->pdid}; - if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) { + ret = ib_respond_udata(udata, uresp); + if (ret) { c4iw_deallocate_pd(&php->ibpd, udata); - return -EFAULT; + return ret; } } mutex_lock(&rhp->rdev.stats.lock); diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c index d9a86e4c54618..f9c7030ac6bfd 100644 --- a/drivers/infiniband/hw/cxgb4/qp.c +++ b/drivers/infiniband/hw/cxgb4/qp.c @@ -2280,7 +2280,7 @@ int c4iw_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *attrs, ucontext->key += PAGE_SIZE; } spin_unlock(&ucontext->mmap_lock); - ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + ret = ib_respond_udata(udata, uresp); if (ret) goto err_free_ma_sync_key; sq_key_mm->key = uresp.sq_key; @@ -2777,7 +2777,7 @@ int c4iw_create_srq(struct ib_srq *ib_srq, struct ib_srq_init_attr *attrs, uresp.srq_db_gts_key = ucontext->key; ucontext->key += PAGE_SIZE; spin_unlock(&ucontext->mmap_lock); - ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + ret = ib_respond_udata(udata, uresp); if (ret) goto err_free_srq_db_key_mm; srq_key_mm->key = uresp.srq_key; diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c index 9bba470c6e325..92a65970ab6fa 100644 --- a/drivers/infiniband/hw/erdma/erdma_verbs.c +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c @@ -1055,7 +1055,7 @@ int erdma_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs, uresp.qp_id = QP_ID(qp); uresp.rq_offset = qp->user_qp.rq_offset; - ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + ret = ib_respond_udata(udata, uresp); if (ret) goto err_out_cmd; } else { @@ -1571,7 +1571,7 @@ int erdma_alloc_ucontext(struct ib_ucontext *ibctx, struct ib_udata *udata) uresp.dev_id = dev->pdev->device; - ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + ret = ib_respond_udata(udata, uresp); if (ret) goto err_put_mmap_entries; diff --git a/drivers/infiniband/hw/ionic/ionic_controlpath.c b/drivers/infiniband/hw/ionic/ionic_controlpath.c index 7051a81cca942..2b01345848ddb 100644 --- a/drivers/infiniband/hw/ionic/ionic_controlpath.c +++ b/drivers/infiniband/hw/ionic/ionic_controlpath.c @@ -414,7 +414,7 @@ int ionic_alloc_ucontext(struct ib_ucontext *ibctx, struct ib_udata *udata) if (dev->lif_cfg.rq_expdb) resp.expdb_qtypes |= IONIC_EXPDB_RQ; - rc = ib_copy_to_udata(udata, &resp, sizeof(resp)); + rc = ib_respond_udata(udata, resp); if (rc) goto err_resp; @@ -752,7 +752,7 @@ int ionic_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, if (udata) { resp.ahid = ah->ahid; - rc = ib_copy_to_udata(udata, &resp, sizeof(resp)); + rc = ib_respond_udata(udata, resp); if (rc) goto err_resp; } @@ -1263,7 +1263,7 @@ int ionic_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, if (udata) { resp.udma_mask = vcq->udma_mask; - rc = ib_copy_to_udata(udata, &resp, sizeof(resp)); + rc = ib_respond_udata(udata, resp); if (rc) goto err_resp; } @@ -2315,7 +2315,7 @@ int ionic_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr, resp.rq_cmb = qp->rq_cmb; } - rc = ib_copy_to_udata(udata, &resp, sizeof(resp)); + rc = ib_respond_udata(udata, resp); if (rc) goto err_resp; } diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/qp.c index 1538aec6d85cc..c50a1eafee58c 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -210,13 +210,9 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd, if (ret) goto fail; - ret = ib_copy_to_udata(udata, &resp, sizeof(resp)); - if (ret) { - ibdev_dbg(&mdev->ib_dev, - "Failed to copy to udata create rss-qp, %d\n", - ret); + ret = ib_respond_udata(udata, resp); + if (ret) goto fail; - } kfree(mana_ind_table); @@ -349,13 +345,9 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd, resp.cqid = send_cq->queue.id; resp.tx_vp_offset = pd->tx_vp_offset; - err = ib_copy_to_udata(udata, &resp, sizeof(resp)); - if (err) { - ibdev_dbg(&mdev->ib_dev, - "Failed copy udata for create qp-raw, %d\n", - err); + err = ib_respond_udata(udata, resp); + if (err) goto err_remove_cq_cb; - } return 0; diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index 16e9ce8138cb3..ce77e893065c9 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -1121,16 +1121,16 @@ static int mlx4_ib_alloc_ucontext(struct ib_ucontext *uctx, mutex_init(&context->wqn_ranges_mutex); if (ibdev->ops.uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION) - err = ib_copy_to_udata(udata, &resp_v3, sizeof(resp_v3)); + err = ib_respond_udata(udata, resp_v3); else - err = ib_copy_to_udata(udata, &resp, sizeof(resp)); + err = ib_respond_udata(udata, resp); if (err) { mlx4_uar_free(to_mdev(ibdev)->dev, &context->uar); - return -EFAULT; + return err; } - return err; + return 0; } static void mlx4_ib_dealloc_ucontext(struct ib_ucontext *ibcontext) diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 01b21530e390b..e70d32001c5be 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -2796,9 +2796,10 @@ static int mlx5_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) pd->uid = uid; if (udata) { resp.pdn = pd->pdn; - if (ib_copy_to_udata(udata, &resp, sizeof(resp))) { + err = ib_respond_udata(udata, resp); + if (err) { mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid); - return -EFAULT; + return err; } } diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c index e8d5d865c1f1f..07c60797c8609 100644 --- a/drivers/infiniband/hw/mthca/mthca_provider.c +++ b/drivers/infiniband/hw/mthca/mthca_provider.c @@ -311,10 +311,11 @@ static int mthca_alloc_ucontext(struct ib_ucontext *uctx, return err; } - if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) { + err = ib_respond_udata(udata, uresp); + if (err) { mthca_cleanup_user_db_tab(to_mdev(ibdev), &context->uar, context->db_tab); mthca_uar_free(to_mdev(ibdev), &context->uar); - return -EFAULT; + return err; } context->reg_mr_warned = 0; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index c17e2a54dbcaf..083f23fc687b3 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -502,7 +502,7 @@ int ocrdma_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata) resp.dpp_wqe_size = dev->attr.wqe_size; memcpy(resp.fw_ver, dev->attr.fw_ver, sizeof(resp.fw_ver)); - status = ib_copy_to_udata(udata, &resp, sizeof(resp)); + status = ib_respond_udata(udata, resp); if (status) goto cpy_err; return 0; @@ -611,7 +611,7 @@ static int ocrdma_copy_pd_uresp(struct ocrdma_dev *dev, struct ocrdma_pd *pd, rsp.dpp_page_addr_lo = dpp_page_addr; } - status = ib_copy_to_udata(udata, &rsp, sizeof(rsp)); + status = ib_respond_udata(udata, rsp); if (status) goto ucopy_err; @@ -945,12 +945,9 @@ static int ocrdma_copy_cq_uresp(struct ocrdma_dev *dev, struct ocrdma_cq *cq, uresp.db_page_addr = ocrdma_get_db_addr(dev, uctx->cntxt_pd->id); uresp.db_page_size = dev->nic_info.db_page_size; uresp.phase_change = cq->phase_change ? 1 : 0; - status = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); - if (status) { - pr_err("%s(%d) copy error cqid=0x%x.\n", - __func__, dev->id, cq->id); + status = ib_respond_udata(udata, uresp); + if (status) goto err; - } status = ocrdma_add_mmap(uctx, uresp.db_page_addr, uresp.db_page_size); if (status) goto err; @@ -1206,11 +1203,9 @@ static int ocrdma_copy_qp_uresp(struct ocrdma_qp *qp, uresp.dpp_credit = dpp_credit_lmt; uresp.dpp_offset = dpp_offset; } - status = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); - if (status) { - pr_err("%s(%d) user copy error.\n", __func__, dev->id); + status = ib_respond_udata(udata, uresp); + if (status) goto err; - } status = ocrdma_add_mmap(pd->uctx, uresp.sq_page_addr[0], uresp.sq_page_size); if (status) @@ -1754,7 +1749,7 @@ static int ocrdma_copy_srq_uresp(struct ocrdma_dev *dev, struct ocrdma_srq *srq, uresp.db_shift = 16; } - status = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + status = ib_respond_udata(udata, uresp); if (status) return status; status = ocrdma_add_mmap(srq->pd->uctx, uresp.rq_page_addr[0], diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index 679aa6f3a63bc..3b86ea1cf8888 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -1251,15 +1251,10 @@ static int qedr_copy_srq_uresp(struct qedr_dev *dev, struct qedr_srq *srq, struct ib_udata *udata) { struct qedr_create_srq_uresp uresp = {}; - int rc; uresp.srq_id = srq->srq_id; - rc = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); - if (rc) - DP_ERR(dev, "create srq: problem copying data to user space\n"); - - return rc; + return ib_respond_udata(udata, uresp); } static void qedr_copy_rq_uresp(struct qedr_dev *dev, diff --git a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c index 615de9c4209bf..e887f03a84d06 100644 --- a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c +++ b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c @@ -82,7 +82,6 @@ static void usnic_ib_fw_string_to_u64(char *fw_ver_str, u64 *fw_ver) static int usnic_ib_fill_create_qp_resp(struct usnic_ib_qp_grp *qp_grp, struct ib_udata *udata) { - struct usnic_ib_dev *us_ibdev; struct usnic_ib_create_qp_resp resp; struct pci_dev *pdev; struct vnic_dev_bar *bar; @@ -92,7 +91,6 @@ static int usnic_ib_fill_create_qp_resp(struct usnic_ib_qp_grp *qp_grp, memset(&resp, 0, sizeof(resp)); - us_ibdev = qp_grp->vf->pf; pdev = usnic_vnic_get_pdev(qp_grp->vf->vnic); if (!pdev) { usnic_err("Failed to get pdev of qp_grp %d\n", @@ -157,12 +155,9 @@ static int usnic_ib_fill_create_qp_resp(struct usnic_ib_qp_grp *qp_grp, struct usnic_ib_qp_grp_flow, link); resp.transport = default_flow->trans_type; - err = ib_copy_to_udata(udata, &resp, sizeof(resp)); - if (err) { - usnic_err("Failed to copy udata for %s", - dev_name(&us_ibdev->ib_dev.dev)); + err = ib_respond_udata(udata, resp); + if (err) return err; - } return 0; } diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c index bc3adcc1ae67c..d5bfdbfe1376d 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c @@ -203,11 +203,10 @@ int pvrdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, cq->uar = &context->uar; /* Copy udata back. */ - if (ib_copy_to_udata(udata, &cq_resp, sizeof(cq_resp))) { - dev_warn(&dev->pdev->dev, - "failed to copy back udata\n"); + ret = ib_respond_udata(udata, cq_resp); + if (ret) { pvrdma_destroy_cq(&cq->ibcq, udata); - return -EINVAL; + return ret; } } diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c index d31fb692fcaaf..e69eadde6c26e 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c @@ -195,10 +195,10 @@ int pvrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr, spin_unlock_irqrestore(&dev->srq_tbl_lock, flags); /* Copy udata back. */ - if (ib_copy_to_udata(udata, &srq_resp, sizeof(srq_resp))) { - dev_warn(&dev->pdev->dev, "failed to copy back udata\n"); + ret = ib_respond_udata(udata, srq_resp); + if (ret) { pvrdma_destroy_srq(&srq->ibsrq, udata); - return -EINVAL; + return ret; } return 0; diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c index bcd43dc30e21c..69a89f609ada9 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c @@ -320,11 +320,11 @@ int pvrdma_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata) /* copy back to user */ uresp.qp_tab_size = vdev->dsr->caps.max_qp; - ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + ret = ib_respond_udata(udata, uresp); if (ret) { pvrdma_uar_free(vdev, &context->uar); pvrdma_dealloc_ucontext(&context->ibucontext); - return -EFAULT; + return ret; } return 0; @@ -430,11 +430,10 @@ int pvrdma_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) pd_resp.pdn = resp->pd_handle; if (udata) { - if (ib_copy_to_udata(udata, &pd_resp, sizeof(pd_resp))) { - dev_warn(&dev->pdev->dev, - "failed to copy back protection domain\n"); + ret = ib_respond_udata(udata, pd_resp); + if (ret) { pvrdma_dealloc_pd(&pd->ibpd, udata); - return -EFAULT; + return ret; } } diff --git a/drivers/infiniband/sw/rdmavt/cq.c b/drivers/infiniband/sw/rdmavt/cq.c index 30904c6ae852d..45404611c9ce5 100644 --- a/drivers/infiniband/sw/rdmavt/cq.c +++ b/drivers/infiniband/sw/rdmavt/cq.c @@ -372,7 +372,7 @@ int rvt_resize_cq(struct ib_cq *ibcq, unsigned int cqe, struct ib_udata *udata) if (udata && udata->outlen >= sizeof(__u64)) { __u64 offset = 0; - ret = ib_copy_to_udata(udata, &offset, sizeof(offset)); + ret = ib_respond_udata(udata, offset); if (ret) goto bail_free; } diff --git a/drivers/infiniband/sw/rdmavt/qp.c b/drivers/infiniband/sw/rdmavt/qp.c index 816624e0991a0..70e7d08fdce69 100644 --- a/drivers/infiniband/sw/rdmavt/qp.c +++ b/drivers/infiniband/sw/rdmavt/qp.c @@ -1192,8 +1192,7 @@ int rvt_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr, if (!qp->r_rq.wq) { __u64 offset = 0; - ret = ib_copy_to_udata(udata, &offset, - sizeof(offset)); + ret = ib_respond_udata(udata, offset); if (ret) goto bail_qpn; } else { diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c index 1e1d262a4ae2d..b34f3d6547ffc 100644 --- a/drivers/infiniband/sw/siw/siw_verbs.c +++ b/drivers/infiniband/sw/siw/siw_verbs.c @@ -102,7 +102,7 @@ int siw_alloc_ucontext(struct ib_ucontext *base_ctx, struct ib_udata *udata) rv = -EINVAL; goto err_out; } - rv = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + rv = ib_respond_udata(udata, uresp); if (rv) goto err_out; @@ -472,7 +472,7 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs, rv = -EINVAL; goto err_out_xa; } - rv = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + rv = ib_respond_udata(udata, uresp); if (rv) goto err_out_xa; } @@ -1205,7 +1205,7 @@ int siw_create_cq(struct ib_cq *base_cq, const struct ib_cq_init_attr *attr, rv = -EINVAL; goto err_out; } - rv = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + rv = ib_respond_udata(udata, uresp); if (rv) goto err_out; } @@ -1386,7 +1386,7 @@ struct ib_mr *siw_reg_user_mr(struct ib_pd *pd, u64 start, u64 len, rv = -EINVAL; goto err_out; } - rv = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + rv = ib_respond_udata(udata, uresp); if (rv) goto err_out; } @@ -1646,7 +1646,7 @@ int siw_create_srq(struct ib_srq *base_srq, rv = -EINVAL; goto err_out; } - rv = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); + rv = ib_respond_udata(udata, uresp); if (rv) goto err_out; }