public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH rdma-next] RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion
@ 2026-02-26 13:07 Leon Romanovsky
  2026-03-02 10:42 ` Leon Romanovsky
  0 siblings, 1 reply; 2+ messages in thread
From: Leon Romanovsky @ 2026-02-26 13:07 UTC (permalink / raw)
  To: linux-rdma, linux-kernel, Selvin Xavier, Kalesh AP,
	Jason Gunthorpe, Leon Romanovsky, Dennis Dalessandro,
	Chengchang Tang, Junxian Huang, Krzysztof Czurylo,
	Tatyana Nikolova, Yishai Hadas, Bryan Tan, Vishnu Dasa,
	Broadcom internal kernel review list

From: Leon Romanovsky <leonro@nvidia.com>

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.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/hw/bnxt_re/qplib_res.c      |  2 +-
 drivers/infiniband/hw/hfi1/user_exp_rcv.c      |  9 ++++-----
 drivers/infiniband/hw/hns/hns_roce_hem.c       |  7 ++-----
 drivers/infiniband/hw/hns/hns_roce_qp.c        | 13 ++++---------
 drivers/infiniband/hw/irdma/hw.c               |  4 ++--
 drivers/infiniband/hw/mlx4/main.c              |  2 +-
 drivers/infiniband/hw/mlx5/devx.c              |  6 +++---
 drivers/infiniband/hw/mlx5/dm.c                |  2 +-
 drivers/infiniband/hw/mlx5/fs.c                |  6 +++---
 drivers/infiniband/hw/mlx5/main.c              |  8 +++-----
 drivers/infiniband/hw/mlx5/qos.c               |  2 +-
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c    | 15 +++++++--------
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c |  3 +--
 13 files changed, 33 insertions(+), 46 deletions(-)

diff --git a/drivers/infiniband/hw/bnxt_re/qplib_res.c b/drivers/infiniband/hw/bnxt_re/qplib_res.c
index 41ad8c2018fd..fa6b8cd137e5 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_res.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_res.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c
index 5b01070ed66f..a916fe0118b1 100644
--- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c
+++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/hns/hns_roce_hem.c b/drivers/infiniband/hw/hns/hns_roce_hem.c
index 4eaaedcc7652..e7c9e30ad2d8 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hem.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hem.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c
index 5f7ea6c16644..6a2dff4bd2d0 100644
--- a/drivers/infiniband/hw/hns/hns_roce_qp.c
+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c
@@ -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;
 		}
diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c
index f4ae530f56db..6e0466ce83d1 100644
--- a/drivers/infiniband/hw/irdma/hw.c
+++ b/drivers/infiniband/hw/irdma/hw.c
@@ -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;
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 64f961e41e1a..73e17b4339eb 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index 0066b2738ac8..645ebcc0832d 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/mlx5/dm.c b/drivers/infiniband/hw/mlx5/dm.c
index 9972f38ba88a..7a6fe4fea3e2 100644
--- a/drivers/infiniband/hw/mlx5/dm.c
+++ b/drivers/infiniband/hw/mlx5/dm.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/mlx5/fs.c b/drivers/infiniband/hw/mlx5/fs.c
index cbccb0b9ac10..b155baee0017 100644
--- a/drivers/infiniband/hw/mlx5/fs.c
+++ b/drivers/infiniband/hw/mlx5/fs.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 26ee8e763d5e..7528f0d75802 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -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;
diff --git a/drivers/infiniband/hw/mlx5/qos.c b/drivers/infiniband/hw/mlx5/qos.c
index dce92554142a..ab7f5db18c93 100644
--- a/drivers/infiniband/hw/mlx5/qos.c
+++ b/drivers/infiniband/hw/mlx5/qos.c
@@ -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;
 
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index c73d4bbee71f..7383b67e1723 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -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;
diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c
index 0864ad25b9d2..64ce5cf5fb96 100644
--- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c
+++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c
@@ -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;
 

---
base-commit: 4c97e6bb1f2311be3146d5f999702392fc17f91f
change-id: 20260226-complete-alloc-conversion-324aa50d51d0

Best regards,
--  
Leon Romanovsky <leonro@nvidia.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH rdma-next] RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion
  2026-02-26 13:07 [PATCH rdma-next] RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion Leon Romanovsky
@ 2026-03-02 10:42 ` Leon Romanovsky
  0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2026-03-02 10:42 UTC (permalink / raw)
  To: linux-rdma, linux-kernel, Selvin Xavier, Kalesh AP,
	Jason Gunthorpe, Dennis Dalessandro, Chengchang Tang,
	Junxian Huang, Krzysztof Czurylo, Tatyana Nikolova, Yishai Hadas,
	Bryan Tan, Vishnu Dasa, Broadcom internal kernel review list,
	Leon Romanovsky


On Thu, 26 Feb 2026 15:07:50 +0200, Leon Romanovsky wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion
      https://git.kernel.org/rdma/rdma/c/94ff7c59cdfde3

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-02 10:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26 13:07 [PATCH rdma-next] RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion Leon Romanovsky
2026-03-02 10:42 ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox