RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion

Commits bf4afc53b7 ("Convert 'alloc_obj' family to use the new default
GFP_KERNEL argument") and 69050f8d6d ("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>
This commit is contained in:
Leon Romanovsky 2026-02-26 15:07:50 +02:00 committed by Leon Romanovsky
parent 58409f0d4d
commit 94ff7c59cd
13 changed files with 33 additions and 46 deletions

View 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;

View 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;

View 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;

View 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;
}

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;