summaryrefslogtreecommitdiff
path: root/drivers/infiniband/ulp
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/infiniband/ulp
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances: Single allocations: kmalloc(sizeof(TYPE), ...) are replaced with: kmalloc_obj(TYPE, ...) Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...) are replaced with: kmalloc_objs(TYPE, COUNT, ...) Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...) are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...) (where TYPE may also be *VAR) The resulting allocations no longer return "void *", instead returning "TYPE *". Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/infiniband/ulp')
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c6
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c4
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c21
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c4
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c2
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_vlan.c2
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c2
-rw-r--r--drivers/infiniband/ulp/iser/iser_initiator.c5
-rw-r--r--drivers/infiniband/ulp/iser/iser_verbs.c4
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c15
-rw-r--r--drivers/infiniband/ulp/opa_vnic/opa_vnic_encap.c4
-rw-r--r--drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c2
-rw-r--r--drivers/infiniband/ulp/rtrs/rtrs-clt.c23
-rw-r--r--drivers/infiniband/ulp/rtrs/rtrs-srv.c32
-rw-r--r--drivers/infiniband/ulp/rtrs/rtrs.c4
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c25
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c29
17 files changed, 85 insertions, 99 deletions
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index b610d36295bb..54de2be1494b 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -360,7 +360,7 @@ static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_i
if (!rx->rx_ring)
return -ENOMEM;
- t = kmalloc(sizeof(*t), GFP_KERNEL);
+ t = kmalloc_obj(*t, GFP_KERNEL);
if (!t) {
ret = -ENOMEM;
goto err_free_1;
@@ -449,7 +449,7 @@ static int ipoib_cm_req_handler(struct ib_cm_id *cm_id,
int ret;
ipoib_dbg(priv, "REQ arrived\n");
- p = kzalloc(sizeof(*p), GFP_KERNEL);
+ p = kzalloc_obj(*p, GFP_KERNEL);
if (!p)
return -ENOMEM;
p->dev = dev;
@@ -1304,7 +1304,7 @@ struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path
struct ipoib_dev_priv *priv = ipoib_priv(dev);
struct ipoib_cm_tx *tx;
- tx = kzalloc(sizeof(*tx), GFP_ATOMIC);
+ tx = kzalloc_obj(*tx, GFP_ATOMIC);
if (!tx)
return NULL;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 10b0dbda6cd5..44354d661e65 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -59,7 +59,7 @@ struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
struct ipoib_ah *ah;
struct ib_ah *vah;
- ah = kmalloc(sizeof(*ah), GFP_KERNEL);
+ ah = kmalloc_obj(*ah, GFP_KERNEL);
if (!ah)
return ERR_PTR(-ENOMEM);
@@ -422,7 +422,7 @@ static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
ipoib_warn(priv,
"failed send event (status=%d, wrid=%d vend_err %#x)\n",
wc->status, wr_id, wc->vendor_err);
- qp_work = kzalloc(sizeof(*qp_work), GFP_ATOMIC);
+ qp_work = kzalloc_obj(*qp_work, GFP_ATOMIC);
if (!qp_work)
return;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 4a504b7c4293..934d8e5a8f11 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -169,7 +169,7 @@ static void ipoib_schedule_ifupdown_task(struct net_device *dev, bool up)
(!up && !(dev->flags & IFF_UP)))
return;
- work = kmalloc(sizeof(*work), GFP_KERNEL);
+ work = kmalloc_obj(*work, GFP_KERNEL);
if (!work)
return;
work->dev = dev;
@@ -673,7 +673,7 @@ struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev)
{
struct ipoib_path_iter *iter;
- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
+ iter = kmalloc_obj(*iter, GFP_KERNEL);
if (!iter)
return NULL;
@@ -924,7 +924,7 @@ static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)
if (!priv->broadcast)
return NULL;
- path = kzalloc(sizeof(*path), GFP_ATOMIC);
+ path = kzalloc_obj(*path, GFP_ATOMIC);
if (!path)
return NULL;
@@ -1443,7 +1443,7 @@ static struct ipoib_neigh *ipoib_neigh_ctor(u8 *daddr,
{
struct ipoib_neigh *neigh;
- neigh = kzalloc(sizeof(*neigh), GFP_ATOMIC);
+ neigh = kzalloc_obj(*neigh, GFP_ATOMIC);
if (!neigh)
return NULL;
@@ -1593,11 +1593,11 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)
clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
ntbl->htbl = NULL;
- htbl = kzalloc(sizeof(*htbl), GFP_KERNEL);
+ htbl = kzalloc_obj(*htbl, GFP_KERNEL);
if (!htbl)
return -ENOMEM;
size = roundup_pow_of_two(arp_tbl.gc_thresh3);
- buckets = kvcalloc(size, sizeof(*buckets), GFP_KERNEL);
+ buckets = kvzalloc_objs(*buckets, size, GFP_KERNEL);
if (!buckets) {
kfree(htbl);
return -ENOMEM;
@@ -1773,9 +1773,8 @@ static int ipoib_dev_init_default(struct net_device *dev)
ipoib_napi_add(dev);
/* Allocate RX/TX "rings" to hold queued skbs */
- priv->rx_ring = kcalloc(ipoib_recvq_size,
- sizeof(*priv->rx_ring),
- GFP_KERNEL);
+ priv->rx_ring = kzalloc_objs(*priv->rx_ring, ipoib_recvq_size,
+ GFP_KERNEL);
if (!priv->rx_ring)
goto out;
@@ -2278,7 +2277,7 @@ int ipoib_intf_init(struct ib_device *hca, u32 port, const char *name,
struct ipoib_dev_priv *priv;
int rc;
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = kzalloc_obj(*priv, GFP_KERNEL);
if (!priv)
return -ENOMEM;
@@ -2664,7 +2663,7 @@ static int ipoib_add_one(struct ib_device *device)
unsigned int p;
int count = 0;
- dev_list = kmalloc(sizeof(*dev_list), GFP_KERNEL);
+ dev_list = kmalloc_obj(*dev_list, GFP_KERNEL);
if (!dev_list)
return -ENOMEM;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index 8a4ab9ff0a68..7b04186f659e 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -139,7 +139,7 @@ static struct ipoib_mcast *ipoib_mcast_alloc(struct net_device *dev)
{
struct ipoib_mcast *mcast;
- mcast = kzalloc(sizeof(*mcast), GFP_ATOMIC);
+ mcast = kzalloc_obj(*mcast, GFP_ATOMIC);
if (!mcast)
return NULL;
@@ -980,7 +980,7 @@ struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev)
{
struct ipoib_mcast_iter *iter;
- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
+ iter = kmalloc_obj(*iter, GFP_KERNEL);
if (!iter)
return NULL;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index 86983080d28b..55a612ad2b07 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -52,7 +52,7 @@ int ipoib_mcast_attach(struct net_device *dev, struct ib_device *hca,
if (set_qkey) {
ret = -ENOMEM;
- qp_attr = kmalloc(sizeof(*qp_attr), GFP_KERNEL);
+ qp_attr = kmalloc_obj(*qp_attr, GFP_KERNEL);
if (!qp_attr)
goto out;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
index 243e8f555eca..df98b4936c32 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
@@ -274,7 +274,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
priv->child_type == IPOIB_LEGACY_CHILD) {
struct ipoib_vlan_delete_work *work;
- work = kmalloc(sizeof(*work), GFP_KERNEL);
+ work = kmalloc_obj(*work, GFP_KERNEL);
if (!work) {
rc = -ENOMEM;
goto out;
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index dc531fad73de..2e1e97acf342 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -802,7 +802,7 @@ static struct iscsi_endpoint *iscsi_iser_ep_connect(struct Scsi_Host *shost,
if (!ep)
return ERR_PTR(-ENOMEM);
- iser_conn = kzalloc(sizeof(*iser_conn), GFP_KERNEL);
+ iser_conn = kzalloc_obj(*iser_conn, GFP_KERNEL);
if (!iser_conn) {
err = -ENOMEM;
goto failure;
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c
index f5f090dc4f1e..0ae0f7722e0f 100644
--- a/drivers/infiniband/ulp/iser/iser_initiator.c
+++ b/drivers/infiniband/ulp/iser/iser_initiator.c
@@ -240,9 +240,8 @@ int iser_alloc_rx_descriptors(struct iser_conn *iser_conn,
goto alloc_login_buf_fail;
iser_conn->num_rx_descs = session->cmds_max;
- iser_conn->rx_descs = kmalloc_array(iser_conn->num_rx_descs,
- sizeof(struct iser_rx_desc),
- GFP_KERNEL);
+ iser_conn->rx_descs = kmalloc_objs(struct iser_rx_desc,
+ iser_conn->num_rx_descs, GFP_KERNEL);
if (!iser_conn->rx_descs)
goto rx_desc_alloc_fail;
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index 6801b70dc9e0..f08dea6721c4 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -105,7 +105,7 @@ iser_create_fastreg_desc(struct iser_device *device,
enum ib_mr_type mr_type;
int ret;
- desc = kzalloc(sizeof(*desc), GFP_KERNEL);
+ desc = kzalloc_obj(*desc, GFP_KERNEL);
if (!desc)
return ERR_PTR(-ENOMEM);
@@ -305,7 +305,7 @@ struct iser_device *iser_device_find_by_ib_device(struct rdma_cm_id *cma_id)
if (device->ib_device->node_guid == cma_id->device->node_guid)
goto inc_refcnt;
- device = kzalloc(sizeof *device, GFP_KERNEL);
+ device = kzalloc_obj(*device, GFP_KERNEL);
if (!device)
goto out;
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index af811d060cc8..ab5d8790cf87 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -152,9 +152,8 @@ isert_alloc_rx_descriptors(struct isert_conn *isert_conn)
u64 dma_addr;
int i, j;
- isert_conn->rx_descs = kcalloc(ISERT_QP_MAX_RECV_DTOS,
- sizeof(struct iser_rx_desc),
- GFP_KERNEL);
+ isert_conn->rx_descs = kzalloc_objs(struct iser_rx_desc,
+ ISERT_QP_MAX_RECV_DTOS, GFP_KERNEL);
if (!isert_conn->rx_descs)
return -ENOMEM;
@@ -275,7 +274,7 @@ isert_device_get(struct rdma_cm_id *cma_id)
}
}
- device = kzalloc(sizeof(struct isert_device), GFP_KERNEL);
+ device = kzalloc_obj(struct isert_device, GFP_KERNEL);
if (!device) {
mutex_unlock(&device_list_mutex);
return ERR_PTR(-ENOMEM);
@@ -333,8 +332,8 @@ isert_alloc_login_buf(struct isert_conn *isert_conn,
{
int ret;
- isert_conn->login_desc = kzalloc(sizeof(*isert_conn->login_desc),
- GFP_KERNEL);
+ isert_conn->login_desc = kzalloc_obj(*isert_conn->login_desc,
+ GFP_KERNEL);
if (!isert_conn->login_desc)
return -ENOMEM;
@@ -429,7 +428,7 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
isert_dbg("cma_id: %p, portal: %p\n",
cma_id, cma_id->context);
- isert_conn = kzalloc(sizeof(struct isert_conn), GFP_KERNEL);
+ isert_conn = kzalloc_obj(struct isert_conn, GFP_KERNEL);
if (!isert_conn)
return -ENOMEM;
@@ -2269,7 +2268,7 @@ isert_setup_np(struct iscsi_np *np,
struct rdma_cm_id *isert_lid;
int ret;
- isert_np = kzalloc(sizeof(struct isert_np), GFP_KERNEL);
+ isert_np = kzalloc_obj(struct isert_np, GFP_KERNEL);
if (!isert_np)
return -ENOMEM;
diff --git a/drivers/infiniband/ulp/opa_vnic/opa_vnic_encap.c b/drivers/infiniband/ulp/opa_vnic/opa_vnic_encap.c
index 31cd361416ac..6d3dbf45e9f5 100644
--- a/drivers/infiniband/ulp/opa_vnic/opa_vnic_encap.c
+++ b/drivers/infiniband/ulp/opa_vnic/opa_vnic_encap.c
@@ -238,7 +238,7 @@ int opa_vnic_update_mac_tbl(struct opa_vnic_adapter *adapter,
if (!memcmp(mac_addr, empty_mac, ARRAY_SIZE(empty_mac)))
continue;
- node = kzalloc(sizeof(*node), GFP_KERNEL);
+ node = kzalloc_obj(*node, GFP_KERNEL);
if (!node) {
rc = -ENOMEM;
goto updt_done;
@@ -265,7 +265,7 @@ int opa_vnic_update_mac_tbl(struct opa_vnic_adapter *adapter,
(node->index < (loffset + lnum_entries)))
continue;
- new_node = kzalloc(sizeof(*new_node), GFP_KERNEL);
+ new_node = kzalloc_obj(*new_node, GFP_KERNEL);
if (!new_node) {
rc = -ENOMEM;
goto updt_done;
diff --git a/drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c b/drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c
index 071f35711468..6d5f642ff3d3 100644
--- a/drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c
+++ b/drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c
@@ -337,7 +337,7 @@ struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
return ERR_CAST(netdev);
rn = netdev_priv(netdev);
- adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
+ adapter = kzalloc_obj(*adapter, GFP_KERNEL);
if (!adapter) {
rc = -ENOMEM;
goto adapter_err;
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 59e30640f94a..67405a19ea10 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1364,9 +1364,8 @@ static int alloc_path_reqs(struct rtrs_clt_path *clt_path)
enum ib_mr_type mr_type;
int i, err = -ENOMEM;
- clt_path->reqs = kcalloc(clt_path->queue_depth,
- sizeof(*clt_path->reqs),
- GFP_KERNEL);
+ clt_path->reqs = kzalloc_objs(*clt_path->reqs, clt_path->queue_depth,
+ GFP_KERNEL);
if (!clt_path->reqs)
return -ENOMEM;
@@ -1384,7 +1383,7 @@ static int alloc_path_reqs(struct rtrs_clt_path *clt_path)
if (!req->iu)
goto out;
- req->sge = kcalloc(2, sizeof(*req->sge), GFP_KERNEL);
+ req->sge = kzalloc_objs(*req->sge, 2, GFP_KERNEL);
if (!req->sge)
goto out;
@@ -1538,7 +1537,7 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
int cpu;
size_t total_con;
- clt_path = kzalloc(sizeof(*clt_path), GFP_KERNEL);
+ clt_path = kzalloc_obj(*clt_path, GFP_KERNEL);
if (!clt_path)
goto err;
@@ -1547,15 +1546,14 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
* +1: Extra connection for user messages
*/
total_con = con_num + nr_poll_queues + 1;
- clt_path->s.con = kcalloc(total_con, sizeof(*clt_path->s.con),
- GFP_KERNEL);
+ clt_path->s.con = kzalloc_objs(*clt_path->s.con, total_con, GFP_KERNEL);
if (!clt_path->s.con)
goto err_free_path;
clt_path->s.con_num = total_con;
clt_path->s.irq_con_num = con_num + 1;
- clt_path->stats = kzalloc(sizeof(*clt_path->stats), GFP_KERNEL);
+ clt_path->stats = kzalloc_obj(*clt_path->stats, GFP_KERNEL);
if (!clt_path->stats)
goto err_free_con;
@@ -1622,7 +1620,7 @@ static int create_con(struct rtrs_clt_path *clt_path, unsigned int cid)
{
struct rtrs_clt_con *con;
- con = kzalloc(sizeof(*con), GFP_KERNEL);
+ con = kzalloc_obj(*con, GFP_KERNEL);
if (!con)
return -ENOMEM;
@@ -1873,9 +1871,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con,
}
if (!clt_path->rbufs) {
- clt_path->rbufs = kcalloc(queue_depth,
- sizeof(*clt_path->rbufs),
- GFP_KERNEL);
+ clt_path->rbufs = kzalloc_objs(*clt_path->rbufs,
+ queue_depth, GFP_KERNEL);
if (!clt_path->rbufs)
return -ENOMEM;
}
@@ -2730,7 +2727,7 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num,
if (strlen(sessname) >= sizeof(clt->sessname))
return ERR_PTR(-EINVAL);
- clt = kzalloc(sizeof(*clt), GFP_KERNEL);
+ clt = kzalloc_obj(*clt, GFP_KERNEL);
if (!clt)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index 2e09811a10b2..c66929b74805 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -138,14 +138,13 @@ static int rtrs_srv_alloc_ops_ids(struct rtrs_srv_path *srv_path)
struct rtrs_srv_op *id;
int i, ret;
- srv_path->ops_ids = kcalloc(srv->queue_depth,
- sizeof(*srv_path->ops_ids),
- GFP_KERNEL);
+ srv_path->ops_ids = kzalloc_objs(*srv_path->ops_ids, srv->queue_depth,
+ GFP_KERNEL);
if (!srv_path->ops_ids)
goto err;
for (i = 0; i < srv->queue_depth; ++i) {
- id = kzalloc(sizeof(*id), GFP_KERNEL);
+ id = kzalloc_obj(*id, GFP_KERNEL);
if (!id)
goto err;
@@ -589,7 +588,7 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
chunks_per_mr = DIV_ROUND_UP(srv->queue_depth, mrs_num);
}
- srv_path->mrs = kcalloc(mrs_num, sizeof(*srv_path->mrs), GFP_KERNEL);
+ srv_path->mrs = kzalloc_objs(*srv_path->mrs, mrs_num, GFP_KERNEL);
if (!srv_path->mrs)
return -ENOMEM;
@@ -837,7 +836,7 @@ static int process_info_req(struct rtrs_srv_con *con,
strscpy(srv_path->s.sessname, msg->pathname,
sizeof(srv_path->s.sessname));
- rwr = kcalloc(srv_path->mrs_num, sizeof(*rwr), GFP_KERNEL);
+ rwr = kzalloc_objs(*rwr, srv_path->mrs_num, GFP_KERNEL);
if (!rwr)
return -ENOMEM;
@@ -1436,7 +1435,7 @@ static struct rtrs_srv_sess *get_or_create_srv(struct rtrs_srv_ctx *ctx,
}
/* need to allocate a new srv */
- srv = kzalloc(sizeof(*srv), GFP_KERNEL);
+ srv = kzalloc_obj(*srv, GFP_KERNEL);
if (!srv)
return ERR_PTR(-ENOMEM);
@@ -1449,8 +1448,7 @@ static struct rtrs_srv_sess *get_or_create_srv(struct rtrs_srv_ctx *ctx,
device_initialize(&srv->dev);
srv->dev.release = rtrs_srv_dev_release;
- srv->chunks = kcalloc(srv->queue_depth, sizeof(*srv->chunks),
- GFP_KERNEL);
+ srv->chunks = kzalloc_objs(*srv->chunks, srv->queue_depth, GFP_KERNEL);
if (!srv->chunks)
goto err_free_srv;
@@ -1715,7 +1713,7 @@ static int create_con(struct rtrs_srv_path *srv_path,
u32 cq_num, max_send_wr, max_recv_wr, wr_limit;
int err, cq_vector;
- con = kzalloc(sizeof(*con), GFP_KERNEL);
+ con = kzalloc_obj(*con, GFP_KERNEL);
if (!con) {
err = -ENOMEM;
goto err;
@@ -1808,11 +1806,11 @@ static struct rtrs_srv_path *__alloc_path(struct rtrs_srv_sess *srv,
err = -EEXIST;
goto err;
}
- srv_path = kzalloc(sizeof(*srv_path), GFP_KERNEL);
+ srv_path = kzalloc_obj(*srv_path, GFP_KERNEL);
if (!srv_path)
goto err;
- srv_path->stats = kzalloc(sizeof(*srv_path->stats), GFP_KERNEL);
+ srv_path->stats = kzalloc_obj(*srv_path->stats, GFP_KERNEL);
if (!srv_path->stats)
goto err_free_sess;
@@ -1822,14 +1820,12 @@ static struct rtrs_srv_path *__alloc_path(struct rtrs_srv_sess *srv,
srv_path->stats->srv_path = srv_path;
- srv_path->dma_addr = kcalloc(srv->queue_depth,
- sizeof(*srv_path->dma_addr),
- GFP_KERNEL);
+ srv_path->dma_addr = kzalloc_objs(*srv_path->dma_addr, srv->queue_depth,
+ GFP_KERNEL);
if (!srv_path->dma_addr)
goto err_free_percpu;
- srv_path->s.con = kcalloc(con_num, sizeof(*srv_path->s.con),
- GFP_KERNEL);
+ srv_path->s.con = kzalloc_objs(*srv_path->s.con, con_num, GFP_KERNEL);
if (!srv_path->s.con)
goto err_free_dma_addr;
@@ -2162,7 +2158,7 @@ static struct rtrs_srv_ctx *alloc_srv_ctx(struct rtrs_srv_ops *ops)
{
struct rtrs_srv_ctx *ctx;
- ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+ ctx = kzalloc_obj(*ctx, GFP_KERNEL);
if (!ctx)
return NULL;
diff --git a/drivers/infiniband/ulp/rtrs/rtrs.c b/drivers/infiniband/ulp/rtrs/rtrs.c
index bc1208ae8216..f316cbe5e62c 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs.c
@@ -26,7 +26,7 @@ struct rtrs_iu *rtrs_iu_alloc(u32 iu_num, size_t size, gfp_t gfp_mask,
struct rtrs_iu *ius, *iu;
int i;
- ius = kcalloc(iu_num, sizeof(*ius), gfp_mask);
+ ius = kzalloc_objs(*ius, iu_num, gfp_mask);
if (!ius)
return NULL;
for (i = 0; i < iu_num; i++) {
@@ -618,7 +618,7 @@ rtrs_ib_dev_find_or_add(struct ib_device *ib_dev,
goto out_unlock;
}
mutex_unlock(&pool->mutex);
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev)
goto out_err;
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 510f16004ecd..e1dfc097f774 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -225,7 +225,7 @@ static struct srp_iu *srp_alloc_iu(struct srp_host *host, size_t size,
{
struct srp_iu *iu;
- iu = kmalloc(sizeof *iu, gfp_mask);
+ iu = kmalloc_obj(*iu, gfp_mask);
if (!iu)
goto out;
@@ -274,7 +274,7 @@ static int srp_init_ib_qp(struct srp_target_port *target,
struct ib_qp_attr *attr;
int ret;
- attr = kmalloc(sizeof *attr, GFP_KERNEL);
+ attr = kmalloc_obj(*attr, GFP_KERNEL);
if (!attr)
return -ENOMEM;
@@ -418,7 +418,7 @@ static struct srp_fr_pool *srp_create_fr_pool(struct ib_device *device,
if (pool_size <= 0)
goto err;
ret = -ENOMEM;
- pool = kzalloc(struct_size(pool, desc, pool_size), GFP_KERNEL);
+ pool = kzalloc_flex(*pool, desc, pool_size, GFP_KERNEL);
if (!pool)
goto err;
pool->size = pool_size;
@@ -533,7 +533,7 @@ static int srp_create_ch_ib(struct srp_rdma_ch *ch)
const int m = 1 + dev->use_fast_reg * target->mr_per_cmd * 2;
int ret;
- init_attr = kzalloc(sizeof *init_attr, GFP_KERNEL);
+ init_attr = kzalloc_obj(*init_attr, GFP_KERNEL);
if (!init_attr)
return -ENOMEM;
@@ -806,7 +806,7 @@ static int srp_send_req(struct srp_rdma_ch *ch, uint32_t max_iu_len,
char *ipi, *tpi;
int status;
- req = kzalloc(sizeof *req, GFP_KERNEL);
+ req = kzalloc_obj(*req, GFP_KERNEL);
if (!req)
return -ENOMEM;
@@ -2257,12 +2257,10 @@ static int srp_alloc_iu_bufs(struct srp_rdma_ch *ch)
struct srp_target_port *target = ch->target;
int i;
- ch->rx_ring = kcalloc(target->queue_size, sizeof(*ch->rx_ring),
- GFP_KERNEL);
+ ch->rx_ring = kzalloc_objs(*ch->rx_ring, target->queue_size, GFP_KERNEL);
if (!ch->rx_ring)
goto err_no_ring;
- ch->tx_ring = kcalloc(target->queue_size, sizeof(*ch->tx_ring),
- GFP_KERNEL);
+ ch->tx_ring = kzalloc_objs(*ch->tx_ring, target->queue_size, GFP_KERNEL);
if (!ch->tx_ring)
goto err_no_ring;
@@ -2387,7 +2385,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
if (!target->using_rdma_cm) {
ret = -ENOMEM;
- qp_attr = kmalloc(sizeof(*qp_attr), GFP_KERNEL);
+ qp_attr = kmalloc_obj(*qp_attr, GFP_KERNEL);
if (!qp_attr)
goto error;
@@ -3824,8 +3822,7 @@ static ssize_t add_target_store(struct device *dev,
num_online_cpus());
}
- target->ch = kcalloc(target->ch_count, sizeof(*target->ch),
- GFP_KERNEL);
+ target->ch = kzalloc_objs(*target->ch, target->ch_count, GFP_KERNEL);
if (!target->ch)
goto out;
@@ -3960,7 +3957,7 @@ static struct srp_host *srp_add_port(struct srp_device *device, u32 port)
{
struct srp_host *host;
- host = kzalloc(sizeof *host, GFP_KERNEL);
+ host = kzalloc_obj(*host, GFP_KERNEL);
if (!host)
return NULL;
@@ -4010,7 +4007,7 @@ static int srp_add_one(struct ib_device *device)
u64 max_pages_per_mr;
unsigned int flags = 0;
- srp_dev = kzalloc(sizeof(*srp_dev), GFP_KERNEL);
+ srp_dev = kzalloc_obj(*srp_dev, GFP_KERNEL);
if (!srp_dev)
return -ENOMEM;
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index e314e6a84d96..6e371b264054 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -127,7 +127,7 @@ static struct kmem_cache *srpt_cache_get(unsigned int object_size)
return e->c;
}
snprintf(name, sizeof(name), "srpt-%u", object_size);
- e = kmalloc(sizeof(*e), GFP_KERNEL);
+ e = kmalloc_obj(*e, GFP_KERNEL);
if (!e)
return NULL;
refcount_set(&e->ref, 1);
@@ -790,7 +790,7 @@ static struct srpt_ioctx **srpt_alloc_ioctx_ring(struct srpt_device *sdev,
WARN_ON(ioctx_size != sizeof(struct srpt_recv_ioctx) &&
ioctx_size != sizeof(struct srpt_send_ioctx));
- ring = kvmalloc_array(ring_size, sizeof(ring[0]), GFP_KERNEL);
+ ring = kvmalloc_objs(ring[0], ring_size, GFP_KERNEL);
if (!ring)
goto out;
for (i = 0; i < ring_size; ++i) {
@@ -965,8 +965,8 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx,
if (nbufs == 1) {
ioctx->rw_ctxs = &ioctx->s_rw_ctx;
} else {
- ioctx->rw_ctxs = kmalloc_array(nbufs, sizeof(*ioctx->rw_ctxs),
- GFP_KERNEL);
+ ioctx->rw_ctxs = kmalloc_objs(*ioctx->rw_ctxs, nbufs,
+ GFP_KERNEL);
if (!ioctx->rw_ctxs)
return -ENOMEM;
}
@@ -1181,7 +1181,7 @@ static int srpt_init_ch_qp(struct srpt_rdma_ch *ch, struct ib_qp *qp)
WARN_ON_ONCE(ch->using_rdma_cm);
- attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+ attr = kzalloc_obj(*attr, GFP_KERNEL);
if (!attr)
return -ENOMEM;
@@ -1857,7 +1857,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)
WARN_ON(ch->rq_size < 1);
ret = -ENOMEM;
- qp_init = kzalloc(sizeof(*qp_init), GFP_KERNEL);
+ qp_init = kzalloc_obj(*qp_init, GFP_KERNEL);
if (!qp_init)
goto out;
@@ -2089,7 +2089,7 @@ static struct srpt_nexus *srpt_get_nexus(struct srpt_port *sport,
if (nexus)
break;
- tmp_nexus = kzalloc(sizeof(*nexus), GFP_KERNEL);
+ tmp_nexus = kzalloc_obj(*nexus, GFP_KERNEL);
if (!tmp_nexus) {
nexus = ERR_PTR(-ENOMEM);
break;
@@ -2241,9 +2241,9 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
}
ret = -ENOMEM;
- rsp = kzalloc(sizeof(*rsp), GFP_KERNEL);
- rej = kzalloc(sizeof(*rej), GFP_KERNEL);
- rep_param = kzalloc(sizeof(*rep_param), GFP_KERNEL);
+ rsp = kzalloc_obj(*rsp, GFP_KERNEL);
+ rej = kzalloc_obj(*rej, GFP_KERNEL);
+ rep_param = kzalloc_obj(*rep_param, GFP_KERNEL);
if (!rsp || !rej || !rep_param)
goto out;
@@ -2273,7 +2273,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
}
ret = -ENOMEM;
- ch = kzalloc(sizeof(*ch), GFP_KERNEL);
+ ch = kzalloc_obj(*ch, GFP_KERNEL);
if (!ch) {
rej->reason = cpu_to_be32(SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES);
pr_err("rejected SRP_LOGIN_REQ because out of memory.\n");
@@ -3210,8 +3210,7 @@ static int srpt_add_one(struct ib_device *device)
pr_debug("device = %p\n", device);
- sdev = kzalloc(struct_size(sdev, port, device->phys_port_cnt),
- GFP_KERNEL);
+ sdev = kzalloc_flex(*sdev, port, device->phys_port_cnt, GFP_KERNEL);
if (!sdev)
return -ENOMEM;
@@ -3790,7 +3789,7 @@ static struct se_portal_group *srpt_make_tpg(struct se_wwn *wwn,
struct srpt_tpg *stpg;
int res = -ENOMEM;
- stpg = kzalloc(sizeof(*stpg), GFP_KERNEL);
+ stpg = kzalloc_obj(*stpg, GFP_KERNEL);
if (!stpg)
return ERR_PTR(res);
stpg->sport_id = sport_id;
@@ -3847,7 +3846,7 @@ static struct se_wwn *srpt_make_tport(struct target_fabric_configfs *tf,
WARN_ON_ONCE(true);
return &(*papi.port_id)->wwn;
}
- port_id = kzalloc(sizeof(*port_id), GFP_KERNEL);
+ port_id = kzalloc_obj(*port_id, GFP_KERNEL);
if (!port_id) {
srpt_sdev_put(sport->sdev);
return ERR_PTR(-ENOMEM);