public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru•mvista.com>
To: David Miller <davem@davemloft•net>
Cc: Scott Wood <scottwood@freescale•com>,
	linuxppc-dev@ozlabs•org, netdev@vger•kernel.org,
	Andy Fleming <afleming@freescale•com>
Subject: [PATCH 2/8] gianfar: Simplify skb resources freeing code
Date: Mon, 12 Oct 2009 20:00:30 +0400	[thread overview]
Message-ID: <20091012160030.GB2463@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <20091012160000.GA32406@oksana.dev.rtsoft.ru>

Remove dma_free_coherent() from stop_gfar() and gfar_start() calls,
place it into free_skb_resources(). That makes SKB resources management
more understandable, plus free_skb_resources() will be used as a cleanup
routine for gfar_alloc_skb_resources() that will be implemented soon.

Signed-off-by: Anton Vorontsov <avorontsov@ru•mvista.com>
---
 drivers/net/gianfar.c |   53 +++++++++++++++++++++++-------------------------
 1 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 8c7322f..b7881e6 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -806,7 +806,6 @@ void gfar_halt(struct net_device *dev)
 void stop_gfar(struct net_device *dev)
 {
 	struct gfar_private *priv = netdev_priv(dev);
-	struct gfar __iomem *regs = priv->regs;
 	unsigned long flags;
 
 	phy_stop(priv->phydev);
@@ -830,18 +829,13 @@ void stop_gfar(struct net_device *dev)
 	}
 
 	free_skb_resources(priv);
-
-	dma_free_coherent(&priv->ofdev->dev,
-			sizeof(struct txbd8)*priv->tx_ring_size
-			+ sizeof(struct rxbd8)*priv->rx_ring_size,
-			priv->tx_bd_base,
-			gfar_read(&regs->tbase0));
 }
 
 /* If there are any tx skbs or rx skbs still around, free them.
  * Then free tx_skbuff and rx_skbuff */
 static void free_skb_resources(struct gfar_private *priv)
 {
+	struct device *dev = &priv->ofdev->dev;
 	struct rxbd8 *rxbdp;
 	struct txbd8 *txbdp;
 	int i, j;
@@ -849,6 +843,9 @@ static void free_skb_resources(struct gfar_private *priv)
 	/* Go through all the buffer descriptors and free their data buffers */
 	txbdp = priv->tx_bd_base;
 
+	if (!priv->tx_skbuff)
+		goto skip_tx_skbuff;
+
 	for (i = 0; i < priv->tx_ring_size; i++) {
 		if (!priv->tx_skbuff[i])
 			continue;
@@ -867,30 +864,33 @@ static void free_skb_resources(struct gfar_private *priv)
 	}
 
 	kfree(priv->tx_skbuff);
+skip_tx_skbuff:
 
 	rxbdp = priv->rx_bd_base;
 
-	/* rx_skbuff is not guaranteed to be allocated, so only
-	 * free it and its contents if it is allocated */
-	if(priv->rx_skbuff != NULL) {
-		for (i = 0; i < priv->rx_ring_size; i++) {
-			if (priv->rx_skbuff[i]) {
-				dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr,
-						priv->rx_buffer_size,
-						DMA_FROM_DEVICE);
-
-				dev_kfree_skb_any(priv->rx_skbuff[i]);
-				priv->rx_skbuff[i] = NULL;
-			}
-
-			rxbdp->lstatus = 0;
-			rxbdp->bufPtr = 0;
+	if (!priv->rx_skbuff)
+		goto skip_rx_skbuff;
 
-			rxbdp++;
+	for (i = 0; i < priv->rx_ring_size; i++) {
+		if (priv->rx_skbuff[i]) {
+			dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr,
+					 priv->rx_buffer_size,
+					DMA_FROM_DEVICE);
+			dev_kfree_skb_any(priv->rx_skbuff[i]);
+			priv->rx_skbuff[i] = NULL;
 		}
 
-		kfree(priv->rx_skbuff);
+		rxbdp->lstatus = 0;
+		rxbdp->bufPtr = 0;
+		rxbdp++;
 	}
+
+	kfree(priv->rx_skbuff);
+skip_rx_skbuff:
+
+	dma_free_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size +
+			       sizeof(*rxbdp) * priv->rx_ring_size,
+			  priv->tx_bd_base, gfar_read(&priv->regs->tbase0));
 }
 
 void gfar_start(struct net_device *dev)
@@ -1148,11 +1148,8 @@ tx_irq_fail:
 err_irq_fail:
 err_rxalloc_fail:
 rx_skb_fail:
-	free_skb_resources(priv);
 tx_skb_fail:
-	dma_free_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size +
-			       sizeof(*rxbdp) * priv->rx_ring_size,
-			  priv->tx_bd_base, gfar_read(&regs->tbase0));
+	free_skb_resources(priv);
 	return err;
 }
 
-- 
1.6.3.3

  parent reply	other threads:[~2009-10-12 16:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-12 16:00 [PATCH 0/8] gianfar: Add support for hibernation Anton Vorontsov
2009-10-12 16:00 ` [PATCH 1/8] gianfar: Some cleanups for startup_gfar() Anton Vorontsov
2009-10-12 16:00 ` Anton Vorontsov [this message]
2009-10-12 16:00 ` [PATCH 3/8] gianfar: Don't needlessly set the wrap bit for the last RX BD Anton Vorontsov
2009-10-12 16:00 ` [PATCH 4/8] gianfar: Split allocation and initialization steps out of startup_gfar() Anton Vorontsov
2009-10-12 16:00 ` [PATCH 5/8] gianfar: Move tbase/rbase initialization to gfar_init_mac() Anton Vorontsov
2009-10-12 16:00 ` [PATCH 6/8] gianfar: Factor out RX BDs initialization from gfar_new_rxbdp() Anton Vorontsov
2009-10-12 16:00 ` [PATCH 7/8] gianfar: Factor out gfar_init_bds() from gfar_alloc_skb_resources() Anton Vorontsov
2009-10-12 16:00 ` [PATCH 8/8] gianfar: Add support for hibernation Anton Vorontsov
2009-10-13  6:57 ` [PATCH 0/8] " David Miller
2009-10-13 17:22   ` Andy Fleming
2009-10-13 19:09     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091012160030.GB2463@oksana.dev.rtsoft.ru \
    --to=avorontsov@ru$(echo .)mvista.com \
    --cc=afleming@freescale$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=linuxppc-dev@ozlabs$(echo .)org \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=scottwood@freescale$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox