diff mbox series

bcm63xx_enet: simplify the code in bcm_enet_open()

Message ID 20210729070627.23776-1-tangbin@cmss.chinamobile.com
State New
Headers show
Series bcm63xx_enet: simplify the code in bcm_enet_open() | expand

Commit Message

Tang Bin July 29, 2021, 7:06 a.m. UTC
In the function bcm_enet_open(), 'ret = -ENOMEM' can be moved
outside the judgement statement, so redundant assignments can
be removed to simplify the code.

Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

Comments

Florian Fainelli July 29, 2021, 9:23 p.m. UTC | #1
On 7/29/21 12:06 AM, Tang Bin wrote:
> In the function bcm_enet_open(), 'ret = -ENOMEM' can be moved
> outside the judgement statement, so redundant assignments can
> be removed to simplify the code.
> 
> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Jakub Kicinski July 30, 2021, 1:28 p.m. UTC | #2
On Thu, 29 Jul 2021 14:23:28 -0700 Florian Fainelli wrote:
> On 7/29/21 12:06 AM, Tang Bin wrote:

> > In the function bcm_enet_open(), 'ret = -ENOMEM' can be moved

> > outside the judgement statement, so redundant assignments can

> > be removed to simplify the code.

> > 

> > Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>  

> 

> Acked-by: Florian Fainelli <f.fainelli@gmail.com>


I wouldn't, the existing code is more robust IMO, but your call :)

Does not apply to net-next, please rebase.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index 509e10013..c5a3c5774 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -920,13 +920,13 @@  static int bcm_enet_open(struct net_device *dev)
 	memcpy(addr.sa_data, dev->dev_addr, ETH_ALEN);
 	bcm_enet_set_mac_address(dev, &addr);
 
+	ret = -ENOMEM;
+
 	/* 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);
-	if (!p) {
-		ret = -ENOMEM;
+	if (!p)
 		goto out_freeirq_tx;
-	}
 
 	priv->rx_desc_alloc_size = size;
 	priv->rx_desc_cpu = p;
@@ -934,20 +934,16 @@  static int bcm_enet_open(struct net_device *dev)
 	/* 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);
-	if (!p) {
-		ret = -ENOMEM;
+	if (!p)
 		goto out_free_rx_ring;
-	}
 
 	priv->tx_desc_alloc_size = size;
 	priv->tx_desc_cpu = p;
 
 	priv->tx_skb = kcalloc(priv->tx_ring_size, sizeof(struct sk_buff *),
 			       GFP_KERNEL);
-	if (!priv->tx_skb) {
-		ret = -ENOMEM;
+	if (!priv->tx_skb)
 		goto out_free_tx_ring;
-	}
 
 	priv->tx_desc_count = priv->tx_ring_size;
 	priv->tx_dirty_desc = 0;
@@ -957,10 +953,8 @@  static int bcm_enet_open(struct net_device *dev)
 	/* init & fill rx ring with skbs */
 	priv->rx_skb = kcalloc(priv->rx_ring_size, sizeof(struct sk_buff *),
 			       GFP_KERNEL);
-	if (!priv->rx_skb) {
-		ret = -ENOMEM;
+	if (!priv->rx_skb)
 		goto out_free_tx_skb;
-	}
 
 	priv->rx_desc_count = 0;
 	priv->rx_dirty_desc = 0;
@@ -976,7 +970,6 @@  static int bcm_enet_open(struct net_device *dev)
 
 	if (bcm_enet_refill_rx(dev)) {
 		dev_err(kdev, "cannot allocate rx skb queue\n");
-		ret = -ENOMEM;
 		goto out;
 	}