Skip to content

Commit

Permalink
drivers:net: dma_alloc_coherent: use __GFP_ZERO instead of memset(, 0)
Browse files Browse the repository at this point in the history
Reduce the number of calls required to alloc
a zeroed block of memory.

Trivially reduces overall object size.

Other changes around these removals
o Neaten call argument alignment
o Remove an unnecessary OOM message after dma_alloc_coherent failure
o Remove unnecessary gfp_t stack variable

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Joe Perches authored and David S. Miller committed Mar 17, 2013
1 parent 7f9421c commit 1f9061d
Show file tree
Hide file tree
Showing 38 changed files with 104 additions and 168 deletions.
8 changes: 2 additions & 6 deletions drivers/net/ethernet/aeroflex/greth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,25 +1466,21 @@ static int greth_of_probe(struct platform_device *ofdev)
/* Allocate TX descriptor ring in coherent memory */
greth->tx_bd_base = dma_alloc_coherent(greth->dev, 1024,
&greth->tx_bd_base_phys,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!greth->tx_bd_base) {
err = -ENOMEM;
goto error3;
}

memset(greth->tx_bd_base, 0, 1024);

/* Allocate RX descriptor ring in coherent memory */
greth->rx_bd_base = dma_alloc_coherent(greth->dev, 1024,
&greth->rx_bd_base_phys,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!greth->rx_bd_base) {
err = -ENOMEM;
goto error4;
}

memset(greth->rx_bd_base, 0, 1024);

/* Get MAC address from: module param, OF property or ID prom */
for (i = 0; i < 6; i++) {
if (macaddr[i] != 0)
Expand Down
8 changes: 4 additions & 4 deletions drivers/net/ethernet/broadcom/bcm63xx_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,25 +862,25 @@ static int bcm_enet_open(struct net_device *dev)

/* allocate rx dma ring */
size = priv->rx_ring_size * sizeof(struct bcm_enet_desc);
p = dma_alloc_coherent(kdev, size, &priv->rx_desc_dma, GFP_KERNEL);
p = dma_alloc_coherent(kdev, size, &priv->rx_desc_dma,
GFP_KERNEL | __GFP_ZERO);
if (!p) {
ret = -ENOMEM;
goto out_freeirq_tx;
}

memset(p, 0, size);
priv->rx_desc_alloc_size = size;
priv->rx_desc_cpu = p;

/* allocate tx dma ring */
size = priv->tx_ring_size * sizeof(struct bcm_enet_desc);
p = dma_alloc_coherent(kdev, size, &priv->tx_desc_dma, GFP_KERNEL);
p = dma_alloc_coherent(kdev, size, &priv->tx_desc_dma,
GFP_KERNEL | __GFP_ZERO);
if (!p) {
ret = -ENOMEM;
goto out_free_rx_ring;
}

memset(p, 0, size);
priv->tx_desc_alloc_size = size;
priv->tx_desc_cpu = p;

Expand Down
5 changes: 2 additions & 3 deletions drivers/net/ethernet/broadcom/bnx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,11 @@ bnx2_alloc_mem(struct bnx2 *bp)
sizeof(struct statistics_block);

status_blk = dma_alloc_coherent(&bp->pdev->dev, bp->status_stats_size,
&bp->status_blk_mapping, GFP_KERNEL);
&bp->status_blk_mapping,
GFP_KERNEL | __GFP_ZERO);
if (status_blk == NULL)
goto alloc_mem_err;

memset(status_blk, 0, bp->status_stats_size);

bnapi = &bp->bnx2_napi[0];
bnapi->status_blk.msi = status_blk;
bnapi->hw_tx_cons_ptr =
Expand Down
9 changes: 3 additions & 6 deletions drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
Original file line number Diff line number Diff line change
Expand Up @@ -1946,12 +1946,9 @@ static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id,
bool is_pf);

#define BNX2X_ILT_ZALLOC(x, y, size) \
do { \
x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
if (x) \
memset(x, 0, size); \
} while (0)
#define BNX2X_ILT_ZALLOC(x, y, size) \
x = dma_alloc_coherent(&bp->pdev->dev, size, y, \
GFP_KERNEL | __GFP_ZERO)

#define BNX2X_ILT_FREE(x, y, size) \
do { \
Expand Down
14 changes: 7 additions & 7 deletions drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ extern int int_mode;
} \
} while (0)

#define BNX2X_PCI_ALLOC(x, y, size) \
do { \
x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
if (x == NULL) \
goto alloc_mem_err; \
memset((void *)x, 0, size); \
} while (0)
#define BNX2X_PCI_ALLOC(x, y, size) \
do { \
x = dma_alloc_coherent(&bp->pdev->dev, size, y, \
GFP_KERNEL | __GFP_ZERO); \
if (x == NULL) \
goto alloc_mem_err; \
} while (0)

#define BNX2X_ALLOC(x, size) \
do { \
Expand Down
11 changes: 3 additions & 8 deletions drivers/net/ethernet/broadcom/tg3.c
Original file line number Diff line number Diff line change
Expand Up @@ -8172,11 +8172,9 @@ static int tg3_mem_rx_acquire(struct tg3 *tp)
tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev,
TG3_RX_RCB_RING_BYTES(tp),
&tnapi->rx_rcb_mapping,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!tnapi->rx_rcb)
goto err_out;

memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
}

return 0;
Expand Down Expand Up @@ -8226,24 +8224,21 @@ static int tg3_alloc_consistent(struct tg3 *tp)
tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev,
sizeof(struct tg3_hw_stats),
&tp->stats_mapping,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!tp->hw_stats)
goto err_out;

memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));

for (i = 0; i < tp->irq_cnt; i++) {
struct tg3_napi *tnapi = &tp->napi[i];
struct tg3_hw_status *sblk;

tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev,
TG3_HW_STATUS_SIZE,
&tnapi->status_mapping,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!tnapi->hw_status)
goto err_out;

memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE);
sblk = tnapi->hw_status;

if (tg3_flag(tp, ENABLE_RSS)) {
Expand Down
5 changes: 2 additions & 3 deletions drivers/net/ethernet/brocade/bna/bnad.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,9 +1264,8 @@ bnad_mem_alloc(struct bnad *bnad,
mem_info->mdl[i].len = mem_info->len;
mem_info->mdl[i].kva =
dma_alloc_coherent(&bnad->pcidev->dev,
mem_info->len, &dma_pa,
GFP_KERNEL);

mem_info->len, &dma_pa,
GFP_KERNEL);
if (mem_info->mdl[i].kva == NULL)
goto err_return;

Expand Down
14 changes: 6 additions & 8 deletions drivers/net/ethernet/emulex/benet/be_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q,
q->entry_size = entry_size;
mem->size = len * entry_size;
mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!mem->va)
return -ENOMEM;
memset(mem->va, 0, mem->size);
return 0;
}

Expand Down Expand Up @@ -2569,10 +2568,9 @@ static int be_setup_wol(struct be_adapter *adapter, bool enable)

cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config);
cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (cmd.va == NULL)
return -1;
memset(cmd.va, 0, cmd.size);

if (enable) {
status = pci_write_config_dword(adapter->pdev,
Expand Down Expand Up @@ -3794,12 +3792,13 @@ static int be_ctrl_init(struct be_adapter *adapter)

rx_filter->size = sizeof(struct be_cmd_req_rx_filter);
rx_filter->va = dma_alloc_coherent(&adapter->pdev->dev, rx_filter->size,
&rx_filter->dma, GFP_KERNEL);
&rx_filter->dma,
GFP_KERNEL | __GFP_ZERO);
if (rx_filter->va == NULL) {
status = -ENOMEM;
goto free_mbox;
}
memset(rx_filter->va, 0, rx_filter->size);

mutex_init(&adapter->mbox_lock);
spin_lock_init(&adapter->mcc_lock);
spin_lock_init(&adapter->mcc_cq_lock);
Expand Down Expand Up @@ -3841,10 +3840,9 @@ static int be_stats_init(struct be_adapter *adapter)
cmd->size = sizeof(struct be_cmd_req_get_stats_v1);

cmd->va = dma_alloc_coherent(&adapter->pdev->dev, cmd->size, &cmd->dma,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (cmd->va == NULL)
return -1;
memset(cmd->va, 0, cmd->size);
return 0;
}

Expand Down
5 changes: 2 additions & 3 deletions drivers/net/ethernet/faraday/ftgmac100.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,11 @@ static int ftgmac100_alloc_buffers(struct ftgmac100 *priv)

priv->descs = dma_alloc_coherent(priv->dev,
sizeof(struct ftgmac100_descs),
&priv->descs_dma_addr, GFP_KERNEL);
&priv->descs_dma_addr,
GFP_KERNEL | __GFP_ZERO);
if (!priv->descs)
return -ENOMEM;

memset(priv->descs, 0, sizeof(struct ftgmac100_descs));

/* initialize RX ring */
ftgmac100_rxdes_set_end_of_ring(&priv->descs->rxdes[RX_QUEUE_ENTRIES - 1]);

Expand Down
8 changes: 4 additions & 4 deletions drivers/net/ethernet/faraday/ftmac100.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,13 +732,13 @@ static int ftmac100_alloc_buffers(struct ftmac100 *priv)
{
int i;

priv->descs = dma_alloc_coherent(priv->dev, sizeof(struct ftmac100_descs),
&priv->descs_dma_addr, GFP_KERNEL);
priv->descs = dma_alloc_coherent(priv->dev,
sizeof(struct ftmac100_descs),
&priv->descs_dma_addr,
GFP_KERNEL | __GFP_ZERO);
if (!priv->descs)
return -ENOMEM;

memset(priv->descs, 0, sizeof(struct ftmac100_descs));

/* initialize RX ring */
ftmac100_rxdes_set_end_of_ring(&priv->descs->rxdes[RX_QUEUE_ENTRIES - 1]);

Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/ibm/emac/mal.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,11 @@ static int mal_probe(struct platform_device *ofdev)
(NUM_TX_BUFF * mal->num_tx_chans +
NUM_RX_BUFF * mal->num_rx_chans);
mal->bd_virt = dma_alloc_coherent(&ofdev->dev, bd_size, &mal->bd_dma,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (mal->bd_virt == NULL) {
err = -ENOMEM;
goto fail_unmap;
}
memset(mal->bd_virt, 0, bd_size);

for (i = 0; i < mal->num_tx_chans; ++i)
set_mal_dcrn(mal, MAL_TXCTPR(i), mal->bd_dma +
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/ethernet/intel/e1000/e1000_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,11 @@ static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
txdr->size = ALIGN(txdr->size, 4096);
txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!txdr->desc) {
ret_val = 2;
goto err_nomem;
}
memset(txdr->desc, 0, txdr->size);
txdr->next_to_use = txdr->next_to_clean = 0;

ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF));
Expand Down Expand Up @@ -1075,12 +1074,11 @@ static int e1000_setup_desc_rings(struct e1000_adapter *adapter)

rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!rxdr->desc) {
ret_val = 5;
goto err_nomem;
}
memset(rxdr->desc, 0, rxdr->size);
rxdr->next_to_use = rxdr->next_to_clean = 0;

rctl = er32(RCTL);
Expand Down
2 changes: 0 additions & 2 deletions drivers/net/ethernet/intel/igbvf/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ int igbvf_setup_tx_resources(struct igbvf_adapter *adapter,

tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
&tx_ring->dma, GFP_KERNEL);

if (!tx_ring->desc)
goto err;

Expand Down Expand Up @@ -488,7 +487,6 @@ int igbvf_setup_rx_resources(struct igbvf_adapter *adapter,

rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
&rx_ring->dma, GFP_KERNEL);

if (!rx_ring->desc)
goto err;

Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/intel/ixgb/ixgb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,11 @@ ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
txdr->size = ALIGN(txdr->size, 4096);

txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (!txdr->desc) {
vfree(txdr->buffer_info);
return -ENOMEM;
}
memset(txdr->desc, 0, txdr->size);

txdr->next_to_use = 0;
txdr->next_to_clean = 0;
Expand Down
16 changes: 9 additions & 7 deletions drivers/net/ethernet/marvell/pxa168_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,14 @@ static int init_hash_table(struct pxa168_eth_private *pep)
*/
if (pep->htpr == NULL) {
pep->htpr = dma_alloc_coherent(pep->dev->dev.parent,
HASH_ADDR_TABLE_SIZE,
&pep->htpr_dma, GFP_KERNEL);
HASH_ADDR_TABLE_SIZE,
&pep->htpr_dma,
GFP_KERNEL | __GFP_ZERO);
if (pep->htpr == NULL)
return -ENOMEM;
} else {
memset(pep->htpr, 0, HASH_ADDR_TABLE_SIZE);
}
memset(pep->htpr, 0, HASH_ADDR_TABLE_SIZE);
wrl(pep, HTPR, pep->htpr_dma);
return 0;
}
Expand Down Expand Up @@ -1023,11 +1025,11 @@ static int rxq_init(struct net_device *dev)
size = pep->rx_ring_size * sizeof(struct rx_desc);
pep->rx_desc_area_size = size;
pep->p_rx_desc_area = dma_alloc_coherent(pep->dev->dev.parent, size,
&pep->rx_desc_dma, GFP_KERNEL);
&pep->rx_desc_dma,
GFP_KERNEL | __GFP_ZERO);
if (!pep->p_rx_desc_area)
goto out;

memset((void *)pep->p_rx_desc_area, 0, size);
/* initialize the next_desc_ptr links in the Rx descriptors ring */
p_rx_desc = pep->p_rx_desc_area;
for (i = 0; i < rx_desc_num; i++) {
Expand Down Expand Up @@ -1084,10 +1086,10 @@ static int txq_init(struct net_device *dev)
size = pep->tx_ring_size * sizeof(struct tx_desc);
pep->tx_desc_area_size = size;
pep->p_tx_desc_area = dma_alloc_coherent(pep->dev->dev.parent, size,
&pep->tx_desc_dma, GFP_KERNEL);
&pep->tx_desc_dma,
GFP_KERNEL | __GFP_ZERO);
if (!pep->p_tx_desc_area)
goto out;
memset((void *)pep->p_tx_desc_area, 0, pep->tx_desc_area_size);
/* Initialize the next_desc_ptr links in the Tx descriptors ring */
p_tx_desc = pep->p_tx_desc_area;
for (i = 0; i < tx_desc_num; i++) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/myricom/myri10ge/myri10ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -3592,10 +3592,9 @@ static int myri10ge_alloc_slices(struct myri10ge_priv *mgp)
bytes = mgp->max_intr_slots * sizeof(*ss->rx_done.entry);
ss->rx_done.entry = dma_alloc_coherent(&pdev->dev, bytes,
&ss->rx_done.bus,
GFP_KERNEL);
GFP_KERNEL | __GFP_ZERO);
if (ss->rx_done.entry == NULL)
goto abort;
memset(ss->rx_done.entry, 0, bytes);
bytes = sizeof(*ss->fw_stats);
ss->fw_stats = dma_alloc_coherent(&pdev->dev, bytes,
&ss->fw_stats_bus,
Expand Down
Loading

0 comments on commit 1f9061d

Please sign in to comment.