Skip to content

Commit aa006d1

Browse files
himanshujha199640davem330
authored andcommitted
ethernet/broadcom: Use zeroing memory allocator than allocator/memset
Use dma_zalloc_coherent for allocating zeroed memory and remove unnecessary memset function. Done using Coccinelle. Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci 0-day tested with no failures. Suggested-by: Luis R. Rodriguez <mcgrof@kernel.org> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5f58dff commit aa006d1

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

drivers/net/ethernet/broadcom/bcm63xx_enet.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,27 +2128,25 @@ static int bcm_enetsw_open(struct net_device *dev)
21282128

21292129
/* allocate rx dma ring */
21302130
size = priv->rx_ring_size * sizeof(struct bcm_enet_desc);
2131-
p = dma_alloc_coherent(kdev, size, &priv->rx_desc_dma, GFP_KERNEL);
2131+
p = dma_zalloc_coherent(kdev, size, &priv->rx_desc_dma, GFP_KERNEL);
21322132
if (!p) {
21332133
dev_err(kdev, "cannot allocate rx ring %u\n", size);
21342134
ret = -ENOMEM;
21352135
goto out_freeirq_tx;
21362136
}
21372137

2138-
memset(p, 0, size);
21392138
priv->rx_desc_alloc_size = size;
21402139
priv->rx_desc_cpu = p;
21412140

21422141
/* allocate tx dma ring */
21432142
size = priv->tx_ring_size * sizeof(struct bcm_enet_desc);
2144-
p = dma_alloc_coherent(kdev, size, &priv->tx_desc_dma, GFP_KERNEL);
2143+
p = dma_zalloc_coherent(kdev, size, &priv->tx_desc_dma, GFP_KERNEL);
21452144
if (!p) {
21462145
dev_err(kdev, "cannot allocate tx ring\n");
21472146
ret = -ENOMEM;
21482147
goto out_free_rx_ring;
21492148
}
21502149

2151-
memset(p, 0, size);
21522150
priv->tx_desc_alloc_size = size;
21532151
priv->tx_desc_cpu = p;
21542152

drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,11 @@ static int bnxt_hwrm_set_dcbx_app(struct bnxt *bp, struct dcb_app *app,
278278

279279
n = IEEE_8021QAZ_MAX_TCS;
280280
data_len = sizeof(*data) + sizeof(*fw_app) * n;
281-
data = dma_alloc_coherent(&bp->pdev->dev, data_len, &mapping,
282-
GFP_KERNEL);
281+
data = dma_zalloc_coherent(&bp->pdev->dev, data_len, &mapping,
282+
GFP_KERNEL);
283283
if (!data)
284284
return -ENOMEM;
285285

286-
memset(data, 0, data_len);
287286
bnxt_hwrm_cmd_hdr_init(bp, &get, HWRM_FW_GET_STRUCTURED_DATA, -1, -1);
288287
get.dest_data_addr = cpu_to_le64(mapping);
289288
get.structure_id = cpu_to_le16(STRUCT_HDR_STRUCT_ID_DCBX_APP);

0 commit comments

Comments
 (0)