]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion
authorLeon Romanovsky <leonro@nvidia.com>
Thu, 26 Feb 2026 13:07:50 +0000 (15:07 +0200)
committerLeon Romanovsky <leon@kernel.org>
Mon, 2 Mar 2026 10:41:24 +0000 (05:41 -0500)
Commits bf4afc53b77a ("Convert 'alloc_obj' family to use the new default
GFP_KERNEL argument") and 69050f8d6d07 ("treewide: Replace kmalloc with
kmalloc_obj for non-scalar types") updated various k[z|m|c]alloc calls to their
k[z|m]alloc_obj counterparts.

This commit finalizes that transition within the RDMA subsystem.

Link: https://patch.msgid.link/20260226-complete-alloc-conversion-v1-1-ebf1df1c2518@nvidia.com
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
13 files changed:
drivers/infiniband/hw/bnxt_re/qplib_res.c
drivers/infiniband/hw/hfi1/user_exp_rcv.c
drivers/infiniband/hw/hns/hns_roce_hem.c
drivers/infiniband/hw/hns/hns_roce_qp.c
drivers/infiniband/hw/irdma/hw.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/devx.c
drivers/infiniband/hw/mlx5/dm.c
drivers/infiniband/hw/mlx5/fs.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/qos.c
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c

index 41ad8c2018fdcd4e6d6bbf4a777410f944f42f7e..fa6b8cd137e5c6d84371a0c306aff58be75c30b8 100644 (file)
@@ -790,7 +790,7 @@ static int bnxt_qplib_alloc_dpi_tbl(struct bnxt_qplib_res *res,
        if (dev_attr->max_dpi)
                dpit->max = min_t(u32, dpit->max, dev_attr->max_dpi);
 
-       dpit->app_tbl = kcalloc(dpit->max,  sizeof(void *), GFP_KERNEL);
+       dpit->app_tbl = kzalloc_objs(void *, dpit->max);
        if (!dpit->app_tbl)
                return -ENOMEM;
 
index 5b01070ed66f81b60cc7855e68bfb4dbda010db3..a916fe0118b10c9a8bdc542cb8cd0b28c7dd14ad 100644 (file)
@@ -257,7 +257,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
        if (tinfo->length == 0)
                return -EINVAL;
 
-       tidbuf = kzalloc(sizeof(*tidbuf), GFP_KERNEL);
+       tidbuf = kzalloc_obj(*tidbuf);
        if (!tidbuf)
                return -ENOMEM;
 
@@ -265,8 +265,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
        tidbuf->vaddr = tinfo->vaddr;
        tidbuf->length = tinfo->length;
        tidbuf->npages = num_user_pages(tidbuf->vaddr, tidbuf->length);
-       tidbuf->psets = kcalloc(uctxt->expected_count, sizeof(*tidbuf->psets),
-                               GFP_KERNEL);
+       tidbuf->psets = kzalloc_objs(*tidbuf->psets, uctxt->expected_count);
        if (!tidbuf->psets) {
                ret = -ENOMEM;
                goto fail_release_mem;
@@ -306,7 +305,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
        }
 
        ngroups = pageset_count / dd->rcv_entries.group_size;
-       tidlist = kcalloc(pageset_count, sizeof(*tidlist), GFP_KERNEL);
+       tidlist = kzalloc_objs(*tidlist, pageset_count);
        if (!tidlist) {
                ret = -ENOMEM;
                goto fail_unreserve;
@@ -527,7 +526,7 @@ int hfi1_user_exp_rcv_invalid(struct hfi1_filedata *fd,
         * for a long time.
         * Copy the data to a local buffer so we can release the lock.
         */
-       array = kcalloc(uctxt->expected_count, sizeof(*array), GFP_KERNEL);
+       array = kzalloc_objs(*array, uctxt->expected_count);
        if (!array)
                return -EFAULT;
 
index 4eaaedcc76521002670112ce78a66934ad0e48ca..e7c9e30ad2d8b44a21028c13350e928b6393ec1e 100644 (file)
@@ -771,9 +771,7 @@ int hns_roce_init_hem_table(struct hns_roce_dev *hr_dev,
                        unsigned long num_bt_l1;
 
                        num_bt_l1 = DIV_ROUND_UP(num_hem, bt_chunk_num);
-                       table->bt_l1 = kcalloc(num_bt_l1,
-                                              sizeof(*table->bt_l1),
-                                              GFP_KERNEL);
+                       table->bt_l1 = kzalloc_objs(*table->bt_l1, num_bt_l1);
                        if (!table->bt_l1)
                                goto err_kcalloc_bt_l1;
 
@@ -786,8 +784,7 @@ int hns_roce_init_hem_table(struct hns_roce_dev *hr_dev,
 
                if (check_whether_bt_num_2(type, hop_num) ||
                        check_whether_bt_num_3(type, hop_num)) {
-                       table->bt_l0 = kcalloc(num_bt_l0, sizeof(*table->bt_l0),
-                                              GFP_KERNEL);
+                       table->bt_l0 = kzalloc_objs(*table->bt_l0, num_bt_l0);
                        if (!table->bt_l0)
                                goto err_kcalloc_bt_l0;
 
index 5f7ea6c1664460dac79e98027a8b7088c8bb6d3d..6a2dff4bd2d0fcb2afb5c03bfd115421e43eaace 100644 (file)
@@ -1023,21 +1023,16 @@ static void free_qp_db(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
 static int alloc_kernel_wrid(struct hns_roce_dev *hr_dev,
                             struct hns_roce_qp *hr_qp)
 {
-       struct ib_device *ibdev = &hr_dev->ib_dev;
-       u64 *sq_wrid = NULL;
-       u64 *rq_wrid = NULL;
+       u64 *sq_wrid, *rq_wrid = NULL;
        int ret;
 
-       sq_wrid = kcalloc(hr_qp->sq.wqe_cnt, sizeof(u64), GFP_KERNEL);
-       if (!sq_wrid) {
-               ibdev_err(ibdev, "failed to alloc SQ wrid.\n");
+       sq_wrid = kzalloc_objs(*sq_wrid, hr_qp->sq.wqe_cnt);
+       if (!sq_wrid)
                return -ENOMEM;
-       }
 
        if (hr_qp->rq.wqe_cnt) {
-               rq_wrid = kcalloc(hr_qp->rq.wqe_cnt, sizeof(u64), GFP_KERNEL);
+               rq_wrid = kzalloc_objs(*rq_wrid, hr_qp->rq.wqe_cnt);
                if (!rq_wrid) {
-                       ibdev_err(ibdev, "failed to alloc RQ wrid.\n");
                        ret = -ENOMEM;
                        goto err_sq;
                }
index f4ae530f56db013cb34c08001ec5c42c2871c64d..6e0466ce83d18012efa387be484ef34cf305a5a9 100644 (file)
@@ -1033,7 +1033,7 @@ static int irdma_create_cqp(struct irdma_pci_f *rf)
        if (!cqp->cqp_requests)
                return -ENOMEM;
 
-       cqp->scratch_array = kcalloc(sqsize, sizeof(*cqp->scratch_array), GFP_KERNEL);
+       cqp->scratch_array = kzalloc_objs(*cqp->scratch_array, sqsize);
        if (!cqp->scratch_array) {
                status = -ENOMEM;
                goto err_scratch;
@@ -1942,7 +1942,7 @@ int irdma_rt_init_hw(struct irdma_device *iwdev,
        if (status)
                return status;
 
-       stats_info.pestat = kzalloc(sizeof(*stats_info.pestat), GFP_KERNEL);
+       stats_info.pestat = kzalloc_obj(*stats_info.pestat);
        if (!stats_info.pestat) {
                irdma_cleanup_cm_core(&iwdev->cm_core);
                return -ENOMEM;
index 64f961e41e1ab1c6390967cd678042cd6532ade8..73e17b4339eb60ba41fe0531f91a83d7f7d21e4f 100644 (file)
@@ -2161,7 +2161,7 @@ static int __mlx4_ib_alloc_diag_counters(struct mlx4_ib_dev *ibdev,
        if (!*pdescs)
                return -ENOMEM;
 
-       *offset = kcalloc(num_counters, sizeof(**offset), GFP_KERNEL);
+       *offset = kzalloc_objs(**offset, num_counters);
        if (!*offset)
                goto err;
 
index 0066b2738ac89836db2f239ecbc7fe84be1ef481..645ebcc0832d7fdd940c3911e7a72744f85c1ff5 100644 (file)
@@ -1557,7 +1557,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(
        if (IS_ERR(cmd_out))
                return PTR_ERR(cmd_out);
 
-       obj = kzalloc(sizeof(struct devx_obj), GFP_KERNEL);
+       obj = kzalloc_obj(*obj);
        if (!obj)
                return -ENOMEM;
 
@@ -2158,7 +2158,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_SUBSCRIBE_EVENT)(
                if (err)
                        goto err;
 
-               event_sub = kzalloc(sizeof(*event_sub), GFP_KERNEL);
+               event_sub = kzalloc_obj(*event_sub);
                if (!event_sub) {
                        err = -ENOMEM;
                        goto err;
@@ -2398,7 +2398,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_UMEM_REG)(
        if (err)
                return err;
 
-       obj = kzalloc(sizeof(struct devx_umem), GFP_KERNEL);
+       obj = kzalloc_obj(*obj);
        if (!obj)
                return -ENOMEM;
 
index 9972f38ba88a942aeaa03af6a0d1261d53a416e8..7a6fe4fea3e2c2e067959ce951f188c07ec5f264 100644 (file)
@@ -228,7 +228,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DM_MAP_OP_ADDR)(
        if (!err || err != -ENOENT)
                goto err_unlock;
 
-       op_entry = kzalloc(sizeof(*op_entry), GFP_KERNEL);
+       op_entry = kzalloc_obj(*op_entry);
        if (!op_entry)
                goto err_unlock;
 
index cbccb0b9ac10d70720120c533e839c351a6edfc0..b155baee0017c33288427856128662cd0ac930e9 100644 (file)
@@ -2917,7 +2917,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_FLOW_MATCHER_CREATE)(
        struct mlx5_ib_flow_matcher *obj;
        int err;
 
-       obj = kzalloc(sizeof(struct mlx5_ib_flow_matcher), GFP_KERNEL);
+       obj = kzalloc_obj(*obj);
        if (!obj)
                return -ENOMEM;
 
@@ -3017,7 +3017,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_STEERING_ANCHOR_CREATE)(
        if (err)
                return err;
 
-       obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+       obj = kzalloc_obj(*obj);
        if (!obj)
                return -ENOMEM;
 
@@ -3259,7 +3259,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_FLOW_ACTION_CREATE_PACKET_REFORMAT)(
        if (!mlx5_ib_flow_action_packet_reformat_valid(mdev, dv_prt, ft_type))
                return -EOPNOTSUPP;
 
-       maction = kzalloc(sizeof(*maction), GFP_KERNEL);
+       maction = kzalloc_obj(*maction);
        if (!maction)
                return -ENOMEM;
 
index 26ee8e763d5e3d66c6e15ba6d6fa758fca7f93a3..7528f0d7580229929861f0213ce363a84ab4e21d 100644 (file)
@@ -2244,16 +2244,14 @@ static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx,
 
        mutex_init(&bfregi->lock);
        bfregi->lib_uar_4k = lib_uar_4k;
-       bfregi->count = kcalloc(bfregi->total_num_bfregs, sizeof(*bfregi->count),
-                               GFP_KERNEL);
+       bfregi->count = kzalloc_objs(*bfregi->count, bfregi->total_num_bfregs);
        if (!bfregi->count) {
                err = -ENOMEM;
                goto out_ucap;
        }
 
-       bfregi->sys_pages = kcalloc(bfregi->num_sys_pages,
-                                   sizeof(*bfregi->sys_pages),
-                                   GFP_KERNEL);
+       bfregi->sys_pages =
+               kzalloc_objs(*bfregi->sys_pages, bfregi->num_sys_pages);
        if (!bfregi->sys_pages) {
                err = -ENOMEM;
                goto out_count;
index dce92554142a29137c721c72c7d2734a3a38353e..ab7f5db18c9333009b9c916399e006026ac6b0f7 100644 (file)
@@ -45,7 +45,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_PP_OBJ_ALLOC)(
                return -EINVAL;
 
        dev = to_mdev(c->ibucontext.device);
-       pp_entry = kzalloc(sizeof(*pp_entry), GFP_KERNEL);
+       pp_entry = kzalloc_obj(*pp_entry);
        if (!pp_entry)
                return -ENOMEM;
 
index c73d4bbee71fcf2b01f96117790bec7a7d904b86..7383b67e1723125f2280f9ac91c4d0fcaac97876 100644 (file)
@@ -794,7 +794,7 @@ static int ocrdma_build_pbl_tbl(struct ocrdma_dev *dev, struct ocrdma_hw_mr *mr)
        void *va;
        dma_addr_t pa;
 
-       mr->pbl_table = kzalloc_objs(struct ocrdma_pbl, mr->num_pbls);
+       mr->pbl_table = kzalloc_objs(*mr->pbl_table, mr->num_pbls);
 
        if (!mr->pbl_table)
                return -ENOMEM;
@@ -1253,12 +1253,11 @@ static void ocrdma_set_qp_db(struct ocrdma_dev *dev, struct ocrdma_qp *qp,
 
 static int ocrdma_alloc_wr_id_tbl(struct ocrdma_qp *qp)
 {
-       qp->wqe_wr_id_tbl =
-           kzalloc_objs(*(qp->wqe_wr_id_tbl), qp->sq.max_cnt);
+       qp->wqe_wr_id_tbl = kzalloc_objs(*qp->wqe_wr_id_tbl, qp->sq.max_cnt);
        if (qp->wqe_wr_id_tbl == NULL)
                return -ENOMEM;
-       qp->rqe_wr_id_tbl =
-           kcalloc(qp->rq.max_cnt, sizeof(u64), GFP_KERNEL);
+
+       qp->rqe_wr_id_tbl = kzalloc_objs(*qp->rqe_wr_id_tbl, qp->rq.max_cnt);
        if (qp->rqe_wr_id_tbl == NULL)
                return -ENOMEM;
 
@@ -1788,8 +1787,8 @@ int ocrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr,
                return status;
 
        if (!udata) {
-               srq->rqe_wr_id_tbl = kcalloc(srq->rq.max_cnt, sizeof(u64),
-                                            GFP_KERNEL);
+               srq->rqe_wr_id_tbl =
+                       kzalloc_objs(*srq->rqe_wr_id_tbl, srq->rq.max_cnt);
                if (!srq->rqe_wr_id_tbl) {
                        status = -ENOMEM;
                        goto arm_err;
@@ -2913,7 +2912,7 @@ struct ib_mr *ocrdma_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
        if (!mr)
                return ERR_PTR(-ENOMEM);
 
-       mr->pages = kcalloc(max_num_sg, sizeof(u64), GFP_KERNEL);
+       mr->pages = kzalloc_objs(*mr->pages, max_num_sg);
        if (!mr->pages) {
                status = -ENOMEM;
                goto pl_err;
index 0864ad25b9d2c37853909be76f91e0eeeaa26a16..64ce5cf5fb96fe51757fe706aafeb9d86c106d42 100644 (file)
@@ -65,8 +65,7 @@ int pvrdma_page_dir_init(struct pvrdma_dev *dev, struct pvrdma_page_dir *pdir,
                goto err;
 
        pdir->ntables = PVRDMA_PAGE_DIR_TABLE(npages - 1) + 1;
-       pdir->tables = kcalloc(pdir->ntables, sizeof(*pdir->tables),
-                              GFP_KERNEL);
+       pdir->tables = kzalloc_objs(*pdir->tables, pdir->ntables);
        if (!pdir->tables)
                goto err;