linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bcm63xx_enet: simplify the code in bcm_enet_open()
@ 2021-07-29  7:06 Tang Bin
  2021-07-29 21:23 ` Florian Fainelli
  0 siblings, 1 reply; 3+ messages in thread
From: Tang Bin @ 2021-07-29  7:06 UTC (permalink / raw)
  To: davem, kuba, f.fainelli, bcm-kernel-feedback-list
  Cc: netdev, linux-arm-kernel, linux-kernel, Tang Bin

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(-)

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;
 	}
 
-- 
2.20.1.windows.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bcm63xx_enet: simplify the code in bcm_enet_open()
  2021-07-29  7:06 [PATCH] bcm63xx_enet: simplify the code in bcm_enet_open() Tang Bin
@ 2021-07-29 21:23 ` Florian Fainelli
  2021-07-30 13:28   ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2021-07-29 21:23 UTC (permalink / raw)
  To: Tang Bin, davem, kuba, f.fainelli, bcm-kernel-feedback-list
  Cc: netdev, linux-arm-kernel, linux-kernel

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>
-- 
Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bcm63xx_enet: simplify the code in bcm_enet_open()
  2021-07-29 21:23 ` Florian Fainelli
@ 2021-07-30 13:28   ` Jakub Kicinski
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2021-07-30 13:28 UTC (permalink / raw)
  To: Florian Fainelli, Tang Bin
  Cc: davem, bcm-kernel-feedback-list, netdev, linux-arm-kernel, linux-kernel

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-30 13:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29  7:06 [PATCH] bcm63xx_enet: simplify the code in bcm_enet_open() Tang Bin
2021-07-29 21:23 ` Florian Fainelli
2021-07-30 13:28   ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).