diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/infiniband/ulp/ipoib | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
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/ipoib')
| -rw-r--r-- | drivers/infiniband/ulp/ipoib/ipoib_cm.c | 6 | ||||
| -rw-r--r-- | drivers/infiniband/ulp/ipoib/ipoib_ib.c | 4 | ||||
| -rw-r--r-- | drivers/infiniband/ulp/ipoib/ipoib_main.c | 21 | ||||
| -rw-r--r-- | drivers/infiniband/ulp/ipoib/ipoib_multicast.c | 4 | ||||
| -rw-r--r-- | drivers/infiniband/ulp/ipoib/ipoib_verbs.c | 2 | ||||
| -rw-r--r-- | drivers/infiniband/ulp/ipoib/ipoib_vlan.c | 2 |
6 files changed, 19 insertions, 20 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; |
