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/net/ethernet/synopsys | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-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/net/ethernet/synopsys')
| -rw-r--r-- | drivers/net/ethernet/synopsys/dwc-xlgmac-desc.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/drivers/net/ethernet/synopsys/dwc-xlgmac-desc.c b/drivers/net/ethernet/synopsys/dwc-xlgmac-desc.c index 589797bad1f9..cda6ee474400 100644 --- a/drivers/net/ethernet/synopsys/dwc-xlgmac-desc.c +++ b/drivers/net/ethernet/synopsys/dwc-xlgmac-desc.c @@ -140,9 +140,8 @@ static int xlgmac_init_ring(struct xlgmac_pdata *pdata, return -ENOMEM; /* Array of descriptor data */ - ring->desc_data_head = kcalloc(dma_desc_count, - sizeof(struct xlgmac_desc_data), - GFP_KERNEL); + ring->desc_data_head = kzalloc_objs(struct xlgmac_desc_data, + dma_desc_count, GFP_KERNEL); if (!ring->desc_data_head) return -ENOMEM; @@ -234,21 +233,21 @@ static int xlgmac_alloc_channels(struct xlgmac_pdata *pdata) int ret = -ENOMEM; unsigned int i; - channel_head = kcalloc(pdata->channel_count, - sizeof(struct xlgmac_channel), GFP_KERNEL); + channel_head = kzalloc_objs(struct xlgmac_channel, pdata->channel_count, + GFP_KERNEL); if (!channel_head) return ret; netif_dbg(pdata, drv, pdata->netdev, "channel_head=%p\n", channel_head); - tx_ring = kcalloc(pdata->tx_ring_count, sizeof(struct xlgmac_ring), - GFP_KERNEL); + tx_ring = kzalloc_objs(struct xlgmac_ring, pdata->tx_ring_count, + GFP_KERNEL); if (!tx_ring) goto err_tx_ring; - rx_ring = kcalloc(pdata->rx_ring_count, sizeof(struct xlgmac_ring), - GFP_KERNEL); + rx_ring = kzalloc_objs(struct xlgmac_ring, pdata->rx_ring_count, + GFP_KERNEL); if (!rx_ring) goto err_rx_ring; |
