Commit cd2b0389 authored by Joe Perches's avatar Joe Perches Committed by David S. Miller

bnx2x: Remove hidden flow control goto from BNX2X_ALLOC macros

BNX2X_ALLOC macros use "goto alloc_mem_err"
so these labels appear unused in some functions.

Expand these macros in-place via coccinelle and
some typing.

Update the macros to use statement expressions
and remove the BNX2X_ALLOC macro.

This adds some > 80 char lines.

$ cat bnx2x_pci_alloc.cocci
@@
expression e1;
expression e2;
expression e3;
@@
-	BNX2X_PCI_ALLOC(e1, e2, e3);
+	e1 = BNX2X_PCI_ALLOC(e2, e3); if (!e1) goto alloc_mem_err;

@@
expression e1;
expression e2;
expression e3;
@@
-	BNX2X_PCI_FALLOC(e1, e2, e3);
+	e1 = BNX2X_PCI_FALLOC(e2, e3); if (!e1) goto alloc_mem_err;

@@
expression e1;
expression e2;
@@
-	BNX2X_ALLOC(e1, e2);
+	e1 = kzalloc(e2, GFP_KERNEL); if (!e1) goto alloc_mem_err;

@@
expression e1;
expression e2;
expression e3;
@@
-	kzalloc(sizeof(e1) * e2, e3)
+	kcalloc(e2, sizeof(e1), e3)

@@
expression e1;
expression e2;
expression e3;
@@
-	kzalloc(e1 * sizeof(e2), e3)
+	kcalloc(e1, sizeof(e2), e3)
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 51adfcc3
...@@ -2228,8 +2228,10 @@ static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp) ...@@ -2228,8 +2228,10 @@ static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
sizeof(struct per_queue_stats) * num_queue_stats + sizeof(struct per_queue_stats) * num_queue_stats +
sizeof(struct stats_counter); sizeof(struct stats_counter);
BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping, bp->fw_stats = BNX2X_PCI_ALLOC(&bp->fw_stats_mapping,
bp->fw_stats_data_sz + bp->fw_stats_req_sz); bp->fw_stats_data_sz + bp->fw_stats_req_sz);
if (!bp->fw_stats)
goto alloc_mem_err;
/* Set shortcuts */ /* Set shortcuts */
bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats; bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
...@@ -4357,14 +4359,17 @@ static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index) ...@@ -4357,14 +4359,17 @@ static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index)
if (!IS_FCOE_IDX(index)) { if (!IS_FCOE_IDX(index)) {
/* status blocks */ /* status blocks */
if (!CHIP_IS_E1x(bp)) if (!CHIP_IS_E1x(bp)) {
BNX2X_PCI_ALLOC(sb->e2_sb, sb->e2_sb = BNX2X_PCI_ALLOC(&bnx2x_fp(bp, index, status_blk_mapping),
&bnx2x_fp(bp, index, status_blk_mapping), sizeof(struct host_hc_status_block_e2));
sizeof(struct host_hc_status_block_e2)); if (!sb->e2_sb)
else goto alloc_mem_err;
BNX2X_PCI_ALLOC(sb->e1x_sb, } else {
&bnx2x_fp(bp, index, status_blk_mapping), sb->e1x_sb = BNX2X_PCI_ALLOC(&bnx2x_fp(bp, index, status_blk_mapping),
sizeof(struct host_hc_status_block_e1x)); sizeof(struct host_hc_status_block_e1x));
if (!sb->e1x_sb)
goto alloc_mem_err;
}
} }
/* FCoE Queue uses Default SB and doesn't ACK the SB, thus no need to /* FCoE Queue uses Default SB and doesn't ACK the SB, thus no need to
...@@ -4383,35 +4388,49 @@ static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index) ...@@ -4383,35 +4388,49 @@ static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index)
"allocating tx memory of fp %d cos %d\n", "allocating tx memory of fp %d cos %d\n",
index, cos); index, cos);
BNX2X_ALLOC(txdata->tx_buf_ring, txdata->tx_buf_ring = kcalloc(NUM_TX_BD,
sizeof(struct sw_tx_bd) * NUM_TX_BD); sizeof(struct sw_tx_bd),
BNX2X_PCI_ALLOC(txdata->tx_desc_ring, GFP_KERNEL);
&txdata->tx_desc_mapping, if (!txdata->tx_buf_ring)
sizeof(union eth_tx_bd_types) * NUM_TX_BD); goto alloc_mem_err;
txdata->tx_desc_ring = BNX2X_PCI_ALLOC(&txdata->tx_desc_mapping,
sizeof(union eth_tx_bd_types) * NUM_TX_BD);
if (!txdata->tx_desc_ring)
goto alloc_mem_err;
} }
} }
/* Rx */ /* Rx */
if (!skip_rx_queue(bp, index)) { if (!skip_rx_queue(bp, index)) {
/* fastpath rx rings: rx_buf rx_desc rx_comp */ /* fastpath rx rings: rx_buf rx_desc rx_comp */
BNX2X_ALLOC(bnx2x_fp(bp, index, rx_buf_ring), bnx2x_fp(bp, index, rx_buf_ring) =
sizeof(struct sw_rx_bd) * NUM_RX_BD); kcalloc(NUM_RX_BD, sizeof(struct sw_rx_bd), GFP_KERNEL);
BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_desc_ring), if (!bnx2x_fp(bp, index, rx_buf_ring))
&bnx2x_fp(bp, index, rx_desc_mapping), goto alloc_mem_err;
sizeof(struct eth_rx_bd) * NUM_RX_BD); bnx2x_fp(bp, index, rx_desc_ring) =
BNX2X_PCI_ALLOC(&bnx2x_fp(bp, index, rx_desc_mapping),
sizeof(struct eth_rx_bd) * NUM_RX_BD);
if (!bnx2x_fp(bp, index, rx_desc_ring))
goto alloc_mem_err;
/* Seed all CQEs by 1s */ /* Seed all CQEs by 1s */
BNX2X_PCI_FALLOC(bnx2x_fp(bp, index, rx_comp_ring), bnx2x_fp(bp, index, rx_comp_ring) =
&bnx2x_fp(bp, index, rx_comp_mapping), BNX2X_PCI_FALLOC(&bnx2x_fp(bp, index, rx_comp_mapping),
sizeof(struct eth_fast_path_rx_cqe) * sizeof(struct eth_fast_path_rx_cqe) * NUM_RCQ_BD);
NUM_RCQ_BD); if (!bnx2x_fp(bp, index, rx_comp_ring))
goto alloc_mem_err;
/* SGE ring */ /* SGE ring */
BNX2X_ALLOC(bnx2x_fp(bp, index, rx_page_ring), bnx2x_fp(bp, index, rx_page_ring) =
sizeof(struct sw_rx_page) * NUM_RX_SGE); kcalloc(NUM_RX_SGE, sizeof(struct sw_rx_page),
BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_sge_ring), GFP_KERNEL);
&bnx2x_fp(bp, index, rx_sge_mapping), if (!bnx2x_fp(bp, index, rx_page_ring))
BCM_PAGE_SIZE * NUM_RX_SGE_PAGES); goto alloc_mem_err;
bnx2x_fp(bp, index, rx_sge_ring) =
BNX2X_PCI_ALLOC(&bnx2x_fp(bp, index, rx_sge_mapping),
BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
if (!bnx2x_fp(bp, index, rx_sge_ring))
goto alloc_mem_err;
/* RX BD ring */ /* RX BD ring */
bnx2x_set_next_page_rx_bd(fp); bnx2x_set_next_page_rx_bd(fp);
......
...@@ -47,31 +47,26 @@ extern int bnx2x_num_queues; ...@@ -47,31 +47,26 @@ extern int bnx2x_num_queues;
} \ } \
} while (0) } while (0)
#define BNX2X_PCI_ALLOC(x, y, size) \ #define BNX2X_PCI_ALLOC(y, size) \
do { \ ({ \
x = dma_zalloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \ void *x = dma_zalloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
if (x == NULL) \ if (x) \
goto alloc_mem_err; \ DP(NETIF_MSG_HW, \
DP(NETIF_MSG_HW, "BNX2X_PCI_ALLOC: Physical %Lx Virtual %p\n", \ "BNX2X_PCI_ALLOC: Physical %Lx Virtual %p\n", \
(unsigned long long)(*y), x); \ (unsigned long long)(*y), x); \
} while (0) x; \
})
#define BNX2X_PCI_FALLOC(x, y, size) \ #define BNX2X_PCI_FALLOC(y, size) \
do { \ ({ \
x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \ void *x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
if (x == NULL) \ if (x) { \
goto alloc_mem_err; \ memset(x, 0xff, size); \
memset((void *)x, 0xFFFFFFFF, size); \ DP(NETIF_MSG_HW, \
DP(NETIF_MSG_HW, "BNX2X_PCI_FALLOC: Physical %Lx Virtual %p\n",\ "BNX2X_PCI_FALLOC: Physical %Lx Virtual %p\n", \
(unsigned long long)(*y), x); \ (unsigned long long)(*y), x); \
} while (0) } \
x; \
#define BNX2X_ALLOC(x, size) \ })
do { \
x = kzalloc(size, GFP_KERNEL); \
if (x == NULL) \
goto alloc_mem_err; \
} while (0)
/*********************** Interfaces **************************** /*********************** Interfaces ****************************
* Functions that need to be implemented by each driver version * Functions that need to be implemented by each driver version
......
...@@ -8001,19 +8001,25 @@ void bnx2x_free_mem(struct bnx2x *bp) ...@@ -8001,19 +8001,25 @@ void bnx2x_free_mem(struct bnx2x *bp)
int bnx2x_alloc_mem_cnic(struct bnx2x *bp) int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
{ {
if (!CHIP_IS_E1x(bp)) if (!CHIP_IS_E1x(bp)) {
/* size = the status block + ramrod buffers */ /* size = the status block + ramrod buffers */
BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping, bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
sizeof(struct host_hc_status_block_e2)); sizeof(struct host_hc_status_block_e2));
else if (!bp->cnic_sb.e2_sb)
BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, goto alloc_mem_err;
&bp->cnic_sb_mapping, } else {
sizeof(struct bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
host_hc_status_block_e1x)); sizeof(struct host_hc_status_block_e1x));
if (!bp->cnic_sb.e1x_sb)
goto alloc_mem_err;
}
if (CONFIGURE_NIC_MODE(bp) && !bp->t2) if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
/* allocate searcher T2 table, as it wasn't allocated before */ /* allocate searcher T2 table, as it wasn't allocated before */
BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
if (!bp->t2)
goto alloc_mem_err;
}
/* write address to which L5 should insert its values */ /* write address to which L5 should insert its values */
bp->cnic_eth_dev.addr_drv_info_to_mcp = bp->cnic_eth_dev.addr_drv_info_to_mcp =
...@@ -8034,15 +8040,22 @@ int bnx2x_alloc_mem(struct bnx2x *bp) ...@@ -8034,15 +8040,22 @@ int bnx2x_alloc_mem(struct bnx2x *bp)
{ {
int i, allocated, context_size; int i, allocated, context_size;
if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
/* allocate searcher T2 table */ /* allocate searcher T2 table */
BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
if (!bp->t2)
goto alloc_mem_err;
}
BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
sizeof(struct host_sp_status_block)); sizeof(struct host_sp_status_block));
if (!bp->def_status_blk)
goto alloc_mem_err;
BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
sizeof(struct bnx2x_slowpath)); sizeof(struct bnx2x_slowpath));
if (!bp->slowpath)
goto alloc_mem_err;
/* Allocate memory for CDU context: /* Allocate memory for CDU context:
* This memory is allocated separately and not in the generic ILT * This memory is allocated separately and not in the generic ILT
...@@ -8062,12 +8075,16 @@ int bnx2x_alloc_mem(struct bnx2x *bp) ...@@ -8062,12 +8075,16 @@ int bnx2x_alloc_mem(struct bnx2x *bp)
for (i = 0, allocated = 0; allocated < context_size; i++) { for (i = 0, allocated = 0; allocated < context_size; i++) {
bp->context[i].size = min(CDU_ILT_PAGE_SZ, bp->context[i].size = min(CDU_ILT_PAGE_SZ,
(context_size - allocated)); (context_size - allocated));
BNX2X_PCI_ALLOC(bp->context[i].vcxt, bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
&bp->context[i].cxt_mapping, bp->context[i].size);
bp->context[i].size); if (!bp->context[i].vcxt)
goto alloc_mem_err;
allocated += bp->context[i].size; allocated += bp->context[i].size;
} }
BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES); bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
GFP_KERNEL);
if (!bp->ilt->lines)
goto alloc_mem_err;
if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC)) if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
goto alloc_mem_err; goto alloc_mem_err;
...@@ -8076,11 +8093,15 @@ int bnx2x_alloc_mem(struct bnx2x *bp) ...@@ -8076,11 +8093,15 @@ int bnx2x_alloc_mem(struct bnx2x *bp)
goto alloc_mem_err; goto alloc_mem_err;
/* Slow path ring */ /* Slow path ring */
BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
if (!bp->spq)
goto alloc_mem_err;
/* EQ */ /* EQ */
BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping, bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
BCM_PAGE_SIZE * NUM_EQ_PAGES); BCM_PAGE_SIZE * NUM_EQ_PAGES);
if (!bp->eq_ring)
goto alloc_mem_err;
return 0; return 0;
...@@ -11954,7 +11975,7 @@ static int bnx2x_init_mcast_macs_list(struct bnx2x *bp, ...@@ -11954,7 +11975,7 @@ static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
{ {
int mc_count = netdev_mc_count(bp->dev); int mc_count = netdev_mc_count(bp->dev);
struct bnx2x_mcast_list_elem *mc_mac = struct bnx2x_mcast_list_elem *mc_mac =
kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC); kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
struct netdev_hw_addr *ha; struct netdev_hw_addr *ha;
if (!mc_mac) if (!mc_mac)
......
...@@ -2120,7 +2120,9 @@ int bnx2x_iov_alloc_mem(struct bnx2x *bp) ...@@ -2120,7 +2120,9 @@ int bnx2x_iov_alloc_mem(struct bnx2x *bp)
cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ); cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ);
if (cxt->size) { if (cxt->size) {
BNX2X_PCI_ALLOC(cxt->addr, &cxt->mapping, cxt->size); cxt->addr = BNX2X_PCI_ALLOC(&cxt->mapping, cxt->size);
if (!cxt->addr)
goto alloc_mem_err;
} else { } else {
cxt->addr = NULL; cxt->addr = NULL;
cxt->mapping = 0; cxt->mapping = 0;
...@@ -2130,20 +2132,28 @@ int bnx2x_iov_alloc_mem(struct bnx2x *bp) ...@@ -2130,20 +2132,28 @@ int bnx2x_iov_alloc_mem(struct bnx2x *bp)
/* allocate vfs ramrods dma memory - client_init and set_mac */ /* allocate vfs ramrods dma memory - client_init and set_mac */
tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp); tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp);
BNX2X_PCI_ALLOC(BP_VFDB(bp)->sp_dma.addr, &BP_VFDB(bp)->sp_dma.mapping, BP_VFDB(bp)->sp_dma.addr = BNX2X_PCI_ALLOC(&BP_VFDB(bp)->sp_dma.mapping,
tot_size); tot_size);
if (!BP_VFDB(bp)->sp_dma.addr)
goto alloc_mem_err;
BP_VFDB(bp)->sp_dma.size = tot_size; BP_VFDB(bp)->sp_dma.size = tot_size;
/* allocate mailboxes */ /* allocate mailboxes */
tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE; tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE;
BNX2X_PCI_ALLOC(BP_VF_MBX_DMA(bp)->addr, &BP_VF_MBX_DMA(bp)->mapping, BP_VF_MBX_DMA(bp)->addr = BNX2X_PCI_ALLOC(&BP_VF_MBX_DMA(bp)->mapping,
tot_size); tot_size);
if (!BP_VF_MBX_DMA(bp)->addr)
goto alloc_mem_err;
BP_VF_MBX_DMA(bp)->size = tot_size; BP_VF_MBX_DMA(bp)->size = tot_size;
/* allocate local bulletin boards */ /* allocate local bulletin boards */
tot_size = BNX2X_NR_VIRTFN(bp) * BULLETIN_CONTENT_SIZE; tot_size = BNX2X_NR_VIRTFN(bp) * BULLETIN_CONTENT_SIZE;
BNX2X_PCI_ALLOC(BP_VF_BULLETIN_DMA(bp)->addr, BP_VF_BULLETIN_DMA(bp)->addr = BNX2X_PCI_ALLOC(&BP_VF_BULLETIN_DMA(bp)->mapping,
&BP_VF_BULLETIN_DMA(bp)->mapping, tot_size); tot_size);
if (!BP_VF_BULLETIN_DMA(bp)->addr)
goto alloc_mem_err;
BP_VF_BULLETIN_DMA(bp)->size = tot_size; BP_VF_BULLETIN_DMA(bp)->size = tot_size;
return 0; return 0;
...@@ -3825,12 +3835,16 @@ int bnx2x_vf_pci_alloc(struct bnx2x *bp) ...@@ -3825,12 +3835,16 @@ int bnx2x_vf_pci_alloc(struct bnx2x *bp)
mutex_init(&bp->vf2pf_mutex); mutex_init(&bp->vf2pf_mutex);
/* allocate vf2pf mailbox for vf to pf channel */ /* allocate vf2pf mailbox for vf to pf channel */
BNX2X_PCI_ALLOC(bp->vf2pf_mbox, &bp->vf2pf_mbox_mapping, bp->vf2pf_mbox = BNX2X_PCI_ALLOC(&bp->vf2pf_mbox_mapping,
sizeof(struct bnx2x_vf_mbx_msg)); sizeof(struct bnx2x_vf_mbx_msg));
if (!bp->vf2pf_mbox)
goto alloc_mem_err;
/* allocate pf 2 vf bulletin board */ /* allocate pf 2 vf bulletin board */
BNX2X_PCI_ALLOC(bp->pf2vf_bulletin, &bp->pf2vf_bulletin_mapping, bp->pf2vf_bulletin = BNX2X_PCI_ALLOC(&bp->pf2vf_bulletin_mapping,
sizeof(union pf_vf_bulletin)); sizeof(union pf_vf_bulletin));
if (!bp->pf2vf_bulletin)
goto alloc_mem_err;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment