Netdev List
 help / color / mirror / Atom feed
* [PATCH 07/18] net: ethernet: use wrapper functions of net_ratelimit() to simplify code
From: Kefeng Wang @ 2013-10-15 11:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev
In-Reply-To: <1381837514-50660-1-git-send-email-wangkefeng.wang@huawei.com>

Wrapper functions net_ratelimited_function() and net_XXX_ratelimited()
are called to simplify code.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 drivers/net/ethernet/aeroflex/greth.c            | 16 ++++----
 drivers/net/ethernet/alteon/acenic.c             |  3 +-
 drivers/net/ethernet/arc/emac_main.c             |  7 ++--
 drivers/net/ethernet/broadcom/b44.c              |  4 +-
 drivers/net/ethernet/ethoc.c                     |  4 +-
 drivers/net/ethernet/faraday/ftgmac100.c         | 49 +++++++-----------------
 drivers/net/ethernet/faraday/ftmac100.c          | 45 +++++++---------------
 drivers/net/ethernet/freescale/fec_mpc52xx.c     |  3 +-
 drivers/net/ethernet/ibm/emac/mal.c              | 15 ++------
 drivers/net/ethernet/marvell/mv643xx_eth.c       |  6 +--
 drivers/net/ethernet/marvell/pxa168_eth.c        |  8 +---
 drivers/net/ethernet/marvell/sky2.c              | 42 ++++++++------------
 drivers/net/ethernet/myricom/myri10ge/myri10ge.c |  5 +--
 drivers/net/ethernet/realtek/r8169.c             | 13 +++----
 drivers/net/ethernet/sfc/rx.c                    |  8 ++--
 drivers/net/ethernet/sfc/siena_sriov.c           | 27 +++++--------
 drivers/net/ethernet/ti/davinci_emac.c           |  4 +-
 drivers/net/ethernet/tundra/tsi108_eth.c         | 12 ++----
 18 files changed, 90 insertions(+), 181 deletions(-)

diff --git a/drivers/net/ethernet/aeroflex/greth.c b/drivers/net/ethernet/aeroflex/greth.c
index e066945..6a1a97f 100644
--- a/drivers/net/ethernet/aeroflex/greth.c
+++ b/drivers/net/ethernet/aeroflex/greth.c
@@ -569,8 +569,8 @@ frag_map_error:
 		greth_write_bd(&bdp->stat, 0);
 	}
 map_error:
-	if (net_ratelimit())
-		dev_warn(greth->dev, "Could not create TX DMA mapping\n");
+	net_ratelimited_function(dev_warn,
+		greth->dev, "Could not create TX DMA mapping\n");
 	dev_kfree_skb(skb);
 out:
 	return err;
@@ -778,8 +778,8 @@ static int greth_rx(struct net_device *dev, int limit)
 
 			if (unlikely(skb == NULL)) {
 
-				if (net_ratelimit())
-					dev_warn(&dev->dev, "low on memory - " "packet dropped\n");
+				net_ratelimited_function(dev_warn, &dev->dev,
+						"low on memory - packet dropped\n");
 
 				dev->stats.rx_dropped++;
 
@@ -918,8 +918,8 @@ static int greth_rx_gbit(struct net_device *dev, int limit)
 				greth->rx_skbuff[greth->rx_cur] = newskb;
 				greth_write_bd(&bdp->addr, dma_addr);
 			} else {
-				if (net_ratelimit())
-					dev_warn(greth->dev, "Could not create DMA mapping, dropping packet\n");
+				net_ratelimited_function(dev_warn, greth->dev,
+					"Could not create DMA mapping, dropping packet\n");
 				dev_kfree_skb(newskb);
 				/* reusing current skb, so it is a drop */
 				dev->stats.rx_dropped++;
@@ -934,8 +934,8 @@ static int greth_rx_gbit(struct net_device *dev, int limit)
 			 * table handling should be divided into cleaning and
 			 * filling as the TX part of the driver
 			 */
-			if (net_ratelimit())
-				dev_warn(greth->dev, "Could not allocate SKB, dropping packet\n");
+			net_ratelimited_function(dev_warn, greth->dev,
+				"Could not allocate SKB, dropping packet\n");
 			/* reusing current skb, so it is a drop */
 			dev->stats.rx_dropped++;
 		}
diff --git a/drivers/net/ethernet/alteon/acenic.c b/drivers/net/ethernet/alteon/acenic.c
index 219be1b..432640b 100644
--- a/drivers/net/ethernet/alteon/acenic.c
+++ b/drivers/net/ethernet/alteon/acenic.c
@@ -1799,8 +1799,7 @@ static void ace_load_jumbo_rx_ring(struct net_device *dev, int nr_bufs)
 	clear_bit(0, &ap->jumbo_refill_busy);
 	return;
  error_out:
-	if (net_ratelimit())
-		printk(KERN_INFO "Out of memory when allocating "
+	net_info_ratelimited("Out of memory when allocating "
 		       "jumbo receive buffers\n");
 	goto out;
 }
diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
index 9e16014..fe659b8 100644
--- a/drivers/net/ethernet/arc/emac_main.c
+++ b/drivers/net/ethernet/arc/emac_main.c
@@ -221,8 +221,8 @@ static int arc_emac_rx(struct net_device *ndev, int budget)
 			/* We pre-allocate buffers of MTU size so incoming
 			 * packets won't be split/chained.
 			 */
-			if (net_ratelimit())
-				netdev_err(ndev, "incomplete packet received\n");
+			net_ratelimited_funciton(netdev_err, ndev,
+				"incomplete packet received\n");
 
 			/* Return ownership to EMAC */
 			rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
@@ -258,8 +258,7 @@ static int arc_emac_rx(struct net_device *ndev, int budget)
 		addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
 				      EMAC_BUFFER_SIZE, DMA_FROM_DEVICE);
 		if (dma_mapping_error(&ndev->dev, addr)) {
-			if (net_ratelimit())
-				netdev_err(ndev, "cannot dma map\n");
+			net_ratelimited_function(netdev_err, ndev, "cannot dma map\n");
 			dev_kfree_skb(rx_buff->skb);
 			stats->rx_errors++;
 			continue;
diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
index 9b017d9..7e422dc 100644
--- a/drivers/net/ethernet/broadcom/b44.c
+++ b/drivers/net/ethernet/broadcom/b44.c
@@ -187,8 +187,8 @@ static int b44_wait_bit(struct b44 *bp, unsigned long reg,
 		udelay(10);
 	}
 	if (i == timeout) {
-		if (net_ratelimit())
-			netdev_err(bp->dev, "BUG!  Timeout waiting for bit %08x of register %lx to %s\n",
+		net_ratelimited_function(netdev_err, bp->dev,
+				"BUG!  Timeout waiting for bit %08x of register %lx to %s\n",
 				   bit, reg, clear ? "clear" : "set");
 
 		return -ENODEV;
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index 4de8cfd..b61b56d 100644
--- a/drivers/net/ethernet/ethoc.c
+++ b/drivers/net/ethernet/ethoc.c
@@ -446,10 +446,8 @@ static int ethoc_rx(struct net_device *dev, int limit)
 				dev->stats.rx_bytes += size;
 				netif_receive_skb(skb);
 			} else {
-				if (net_ratelimit())
-					dev_warn(&dev->dev,
+				net_ratelimited_function(dev_warn, &dev->dev,
 					    "low on memory - packet dropped\n");
-
 				dev->stats.rx_dropped++;
 				break;
 			}
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 212f44b..a289337 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -354,42 +354,30 @@ static bool ftgmac100_rx_packet_error(struct ftgmac100 *priv,
 	bool error = false;
 
 	if (unlikely(ftgmac100_rxdes_rx_error(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx err\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx err\n");
 		netdev->stats.rx_errors++;
 		error = true;
 	}
 
 	if (unlikely(ftgmac100_rxdes_crc_error(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx crc err\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx crc err\n");
 		netdev->stats.rx_crc_errors++;
 		error = true;
 	} else if (unlikely(ftgmac100_rxdes_ipcs_err(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx IP checksum err\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx IP checksum err\n");
 		error = true;
 	}
 
 	if (unlikely(ftgmac100_rxdes_frame_too_long(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx frame too long\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx frame too long\n");
 		netdev->stats.rx_length_errors++;
 		error = true;
 	} else if (unlikely(ftgmac100_rxdes_runt(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx runt\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx runt\n");
 		netdev->stats.rx_length_errors++;
 		error = true;
 	} else if (unlikely(ftgmac100_rxdes_odd_nibble(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx odd nibble\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx odd bibble\n");
 		netdev->stats.rx_length_errors++;
 		error = true;
 	}
@@ -403,8 +391,7 @@ static void ftgmac100_rx_drop_packet(struct ftgmac100 *priv)
 	struct ftgmac100_rxdes *rxdes = ftgmac100_current_rxdes(priv);
 	bool done = false;
 
-	if (net_ratelimit())
-		netdev_dbg(netdev, "drop packet %p\n", rxdes);
+	net_ratelimited_function(netdev_dbg, netdev, "drop packet %p\n", rxdes);
 
 	do {
 		if (ftgmac100_rxdes_last_segment(rxdes))
@@ -437,9 +424,7 @@ static bool ftgmac100_rx_packet(struct ftgmac100 *priv, int *processed)
 	/* start processing */
 	skb = netdev_alloc_skb_ip_align(netdev, 128);
 	if (unlikely(!skb)) {
-		if (net_ratelimit())
-			netdev_err(netdev, "rx skb alloc failed\n");
-
+		net_ratelimited_function(netdev_err, netdev, "rx skb alloc failed\n");
 		ftgmac100_rx_drop_packet(priv);
 		return true;
 	}
@@ -723,15 +708,13 @@ static int ftgmac100_alloc_rx_page(struct ftgmac100 *priv,
 
 	page = alloc_page(gfp);
 	if (!page) {
-		if (net_ratelimit())
-			netdev_err(netdev, "failed to allocate rx page\n");
+		net_ratelimited_function(netdev_err, netdev, "failed to allocate rx page\n");
 		return -ENOMEM;
 	}
 
 	map = dma_map_page(priv->dev, page, 0, RX_BUF_SIZE, DMA_FROM_DEVICE);
 	if (unlikely(dma_mapping_error(priv->dev, map))) {
-		if (net_ratelimit())
-			netdev_err(netdev, "failed to map rx page\n");
+		net_ratelimited_function(netdev_err, netdev, "failed to map rx page\n");
 		__free_page(page);
 		return -ENOMEM;
 	}
@@ -1043,8 +1026,8 @@ static int ftgmac100_poll(struct napi_struct *napi, int budget)
 
 	if (status & (FTGMAC100_INT_NO_RXBUF | FTGMAC100_INT_RPKT_LOST |
 		      FTGMAC100_INT_AHB_ERR | FTGMAC100_INT_PHYSTS_CHG)) {
-		if (net_ratelimit())
-			netdev_info(netdev, "[ISR] = 0x%x: %s%s%s%s\n", status,
+		net_ratelimited_function(netdev_info, netdev, "[ISR] = 0x%x: %s%s%s%s\n",
+					status,
 				    status & FTGMAC100_INT_NO_RXBUF ? "NO_RXBUF " : "",
 				    status & FTGMAC100_INT_RPKT_LOST ? "RPKT_LOST " : "",
 				    status & FTGMAC100_INT_AHB_ERR ? "AHB_ERR " : "",
@@ -1145,9 +1128,7 @@ static int ftgmac100_hard_start_xmit(struct sk_buff *skb,
 	dma_addr_t map;
 
 	if (unlikely(skb->len > MAX_PKT_SIZE)) {
-		if (net_ratelimit())
-			netdev_dbg(netdev, "tx packet too big\n");
-
+		net_ratelimited_function(netdev_dbg, netdev, "tx packet too big\n");
 		netdev->stats.tx_dropped++;
 		dev_kfree_skb(skb);
 		return NETDEV_TX_OK;
@@ -1156,9 +1137,7 @@ static int ftgmac100_hard_start_xmit(struct sk_buff *skb,
 	map = dma_map_single(priv->dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
 	if (unlikely(dma_mapping_error(priv->dev, map))) {
 		/* drop packet */
-		if (net_ratelimit())
-			netdev_err(netdev, "map socket buffer failed\n");
-
+		net_ratelimited_function(netdev_err, netdev, "map socket buffer failed\n");
 		netdev->stats.tx_dropped++;
 		dev_kfree_skb(skb);
 		return NETDEV_TX_OK;
diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
index 8be5b40..ec8afe2 100644
--- a/drivers/net/ethernet/faraday/ftmac100.c
+++ b/drivers/net/ethernet/faraday/ftmac100.c
@@ -335,37 +335,27 @@ static bool ftmac100_rx_packet_error(struct ftmac100 *priv,
 	bool error = false;
 
 	if (unlikely(ftmac100_rxdes_rx_error(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx err\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx err\n");
 		netdev->stats.rx_errors++;
 		error = true;
 	}
 
 	if (unlikely(ftmac100_rxdes_crc_error(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx crc err\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx crc err\n");
 		netdev->stats.rx_crc_errors++;
 		error = true;
 	}
 
 	if (unlikely(ftmac100_rxdes_frame_too_long(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx frame too long\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx frame too long\n");
 		netdev->stats.rx_length_errors++;
 		error = true;
 	} else if (unlikely(ftmac100_rxdes_runt(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx runt\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx runt\n");
 		netdev->stats.rx_length_errors++;
 		error = true;
 	} else if (unlikely(ftmac100_rxdes_odd_nibble(rxdes))) {
-		if (net_ratelimit())
-			netdev_info(netdev, "rx odd nibble\n");
-
+		net_ratelimited_function(netdev_info, netdev, "rx odd nibble\n");
 		netdev->stats.rx_length_errors++;
 		error = true;
 	}
@@ -379,8 +369,7 @@ static void ftmac100_rx_drop_packet(struct ftmac100 *priv)
 	struct ftmac100_rxdes *rxdes = ftmac100_current_rxdes(priv);
 	bool done = false;
 
-	if (net_ratelimit())
-		netdev_dbg(netdev, "drop packet %p\n", rxdes);
+	net_ratelimited_function(netdev_dbg, netdev, "drop packet %p\n", rxdes);
 
 	do {
 		if (ftmac100_rxdes_last_segment(rxdes))
@@ -422,9 +411,7 @@ static bool ftmac100_rx_packet(struct ftmac100 *priv, int *processed)
 	/* start processing */
 	skb = netdev_alloc_skb_ip_align(netdev, 128);
 	if (unlikely(!skb)) {
-		if (net_ratelimit())
-			netdev_err(netdev, "rx skb alloc failed\n");
-
+		net_ratelimited_function(netdev_err, netdev, "rx skb alloc failed\n");
 		ftmac100_rx_drop_packet(priv);
 		return true;
 	}
@@ -676,15 +663,13 @@ static int ftmac100_alloc_rx_page(struct ftmac100 *priv,
 
 	page = alloc_page(gfp);
 	if (!page) {
-		if (net_ratelimit())
-			netdev_err(netdev, "failed to allocate rx page\n");
+		net_ratelimited_function(netdev_err, netdev, "failed to allocate rx page\n");
 		return -ENOMEM;
 	}
 
 	map = dma_map_page(priv->dev, page, 0, RX_BUF_SIZE, DMA_FROM_DEVICE);
 	if (unlikely(dma_mapping_error(priv->dev, map))) {
-		if (net_ratelimit())
-			netdev_err(netdev, "failed to map rx page\n");
+		net_ratelimited_function(netdev_err, netdev, "failed to map rx page\n");
 		__free_page(page);
 		return -ENOMEM;
 	}
@@ -919,8 +904,8 @@ static int ftmac100_poll(struct napi_struct *napi, int budget)
 
 	if (status & (FTMAC100_INT_NORXBUF | FTMAC100_INT_RPKT_LOST |
 		      FTMAC100_INT_AHB_ERR | FTMAC100_INT_PHYSTS_CHG)) {
-		if (net_ratelimit())
-			netdev_info(netdev, "[ISR] = 0x%x: %s%s%s%s\n", status,
+		net_ratelimited_function(netdev_info, netdev, "[ISR] = 0x%x: %s%s%s%s\n",
+					status,
 				    status & FTMAC100_INT_NORXBUF ? "NORXBUF " : "",
 				    status & FTMAC100_INT_RPKT_LOST ? "RPKT_LOST " : "",
 				    status & FTMAC100_INT_AHB_ERR ? "AHB_ERR " : "",
@@ -1015,9 +1000,7 @@ static int ftmac100_hard_start_xmit(struct sk_buff *skb, struct net_device *netd
 	dma_addr_t map;
 
 	if (unlikely(skb->len > MAX_PKT_SIZE)) {
-		if (net_ratelimit())
-			netdev_dbg(netdev, "tx packet too big\n");
-
+		net_ratelimited_function(netdev_dbg, netdev, "tx packet too big\n");
 		netdev->stats.tx_dropped++;
 		dev_kfree_skb(skb);
 		return NETDEV_TX_OK;
@@ -1026,9 +1009,7 @@ static int ftmac100_hard_start_xmit(struct sk_buff *skb, struct net_device *netd
 	map = dma_map_single(priv->dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
 	if (unlikely(dma_mapping_error(priv->dev, map))) {
 		/* drop packet */
-		if (net_ratelimit())
-			netdev_err(netdev, "map socket buffer failed\n");
-
+		net_ratelimited_function(netdev_err, netdev, "map socket buffer failed\n");
 		netdev->stats.tx_dropped++;
 		dev_kfree_skb(skb);
 		return NETDEV_TX_OK;
diff --git a/drivers/net/ethernet/freescale/fec_mpc52xx.c b/drivers/net/ethernet/freescale/fec_mpc52xx.c
index 9947765..6b1feeb 100644
--- a/drivers/net/ethernet/freescale/fec_mpc52xx.c
+++ b/drivers/net/ethernet/freescale/fec_mpc52xx.c
@@ -313,8 +313,7 @@ static int mpc52xx_fec_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	unsigned long flags;
 
 	if (bcom_queue_full(priv->tx_dmatsk)) {
-		if (net_ratelimit())
-			dev_err(&dev->dev, "transmit queue overrun\n");
+		net_ratelimited_function(dev_err, &dev->dev, "transmit queue overrun\n");
 		return NETDEV_TX_BUSY;
 	}
 
diff --git a/drivers/net/ethernet/ibm/emac/mal.c b/drivers/net/ethernet/ibm/emac/mal.c
index dac564c..9177345 100644
--- a/drivers/net/ethernet/ibm/emac/mal.c
+++ b/drivers/net/ethernet/ibm/emac/mal.c
@@ -240,20 +240,15 @@ static irqreturn_t mal_serr(int irq, void *dev_instance)
 			/* PLB error, it's probably buggy hardware or
 			 * incorrect physical address in BD (i.e. bug)
 			 */
-			if (net_ratelimit())
-				printk(KERN_ERR
-				       "mal%d: system error, "
-				       "PLB (ESR = 0x%08x)\n",
-				       mal->index, esr);
+			net_err_ratelimited("mal%d: system error, "
+				"PLB (ESR = 0x%08x)\n", mal->index, esr);
 			return IRQ_HANDLED;
 		}
 
 		/* OPB error, it's probably buggy hardware or incorrect
 		 * EBC setup
 		 */
-		if (net_ratelimit())
-			printk(KERN_ERR
-			       "mal%d: system error, OPB (ESR = 0x%08x)\n",
+		net_err_ratelimited("mal%d: system error, OPB (ESR = 0x%08x)\n",
 			       mal->index, esr);
 	}
 	return IRQ_HANDLED;
@@ -318,9 +313,7 @@ static irqreturn_t mal_txde(int irq, void *dev_instance)
 
 	MAL_DBG(mal, "txde %08x" NL, deir);
 
-	if (net_ratelimit())
-		printk(KERN_ERR
-		       "mal%d: TX descriptor error (TXDEIR = 0x%08x)\n",
+	net_err_ratelimited("mal%d: TX descriptor error (TXDEIR = 0x%08x)\n",
 		       mal->index, deir);
 
 	return IRQ_HANDLED;
diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 7fb5677..d1e23d7 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -573,8 +573,7 @@ err:
 
 		if ((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC)) !=
 			(RX_FIRST_DESC | RX_LAST_DESC)) {
-			if (net_ratelimit())
-				netdev_err(mp->dev,
+			net_ratelimited_function(netdev_err, mp->dev,
 					   "received packet spanning multiple descriptors\n");
 		}
 
@@ -818,8 +817,7 @@ static netdev_tx_t mv643xx_eth_xmit(struct sk_buff *skb, struct net_device *dev)
 	}
 
 	if (txq->tx_ring_size - txq->tx_desc_count < MAX_SKB_FRAGS + 1) {
-		if (net_ratelimit())
-			netdev_err(dev, "tx queue full?!\n");
+		net_ratelimited_function(netdev_err, dev, "tx queue full?!\n");
 		kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c
index fff6246..ce36745 100644
--- a/drivers/net/ethernet/marvell/pxa168_eth.c
+++ b/drivers/net/ethernet/marvell/pxa168_eth.c
@@ -744,8 +744,7 @@ static int txq_reclaim(struct net_device *dev, int force)
 			pep->tx_skb[tx_index] = NULL;
 
 		if (cmd_sts & TX_ERROR) {
-			if (net_ratelimit())
-				printk(KERN_ERR "%s: Error in TX\n", dev->name);
+			net_err_ratelimited("%s: Error in TX\n", dev->name);
 			dev->stats.tx_errors++;
 		}
 		dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE);
@@ -832,10 +831,7 @@ static int rxq_process(struct net_device *dev, int budget)
 			stats->rx_dropped++;
 			if ((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC)) !=
 			    (RX_FIRST_DESC | RX_LAST_DESC)) {
-				if (net_ratelimit())
-					printk(KERN_ERR
-					       "%s: Rx pkt on multiple desc\n",
-					       dev->name);
+				net_err_ratelimited("%s: Rx pkt on multiple desc\n", dev->name);
 			}
 			if (cmd_sts & RX_ERROR)
 				stats->rx_errors++;
diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index e09a8c6..42cad5d 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -1250,8 +1250,7 @@ map_page_error:
 			 PCI_DMA_FROMDEVICE);
 
 mapping_error:
-	if (net_ratelimit())
-		dev_warn(&pdev->dev, "%s: rx mapping error\n",
+	net_ratelimited_function(dev_warn, &pdev->dev, "%s: rx mapping error\n",
 			 skb->dev->name);
 	return -EIO;
 }
@@ -1998,8 +1997,8 @@ mapping_unwind:
 	}
 
 mapping_error:
-	if (net_ratelimit())
-		dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name);
+	net_ratelimited_function(dev_warn, &hw->pdev->dev,
+		"%s: tx mapping error\n", dev->name);
 	dev_kfree_skb(skb);
 	return NETDEV_TX_OK;
 }
@@ -2633,8 +2632,7 @@ resubmit:
 error:
 	++dev->stats.rx_errors;
 
-	if (net_ratelimit())
-		netif_info(sky2, rx_err, dev,
+	net_ratelimited_function(netif_info, sky2, rx_err, dev,
 			   "rx error, status 0x%x length %d\n", status, length);
 
 	goto resubmit;
@@ -2809,8 +2807,7 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
 			break;
 
 		default:
-			if (net_ratelimit())
-				pr_warning("unknown status opcode 0x%x\n", opcode);
+			net_warn_ratelimited("unknown status opcode 0x%x\n", opcode);
 		}
 	} while (hw->st_idx != idx);
 
@@ -2828,38 +2825,33 @@ static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status)
 {
 	struct net_device *dev = hw->dev[port];
 
-	if (net_ratelimit())
-		netdev_info(dev, "hw error interrupt status 0x%x\n", status);
+	net_ratelimited_function(netdev_info, dev, "hw error interrupt status 0x%x\n",
+		status);
 
 	if (status & Y2_IS_PAR_RD1) {
-		if (net_ratelimit())
-			netdev_err(dev, "ram data read parity error\n");
+		net_ratelimited_function(netdev_err, dev, "ram data read parity error\n");
 		/* Clear IRQ */
 		sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR);
 	}
 
 	if (status & Y2_IS_PAR_WR1) {
-		if (net_ratelimit())
-			netdev_err(dev, "ram data write parity error\n");
+		net_ratelimited_function(netdev_err, dev, "ram data write parity error\n");
 
 		sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR);
 	}
 
 	if (status & Y2_IS_PAR_MAC1) {
-		if (net_ratelimit())
-			netdev_err(dev, "MAC parity error\n");
+		net_ratelimited_function(netdev_err, dev, "MAC parity error\n");
 		sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE);
 	}
 
 	if (status & Y2_IS_PAR_RX1) {
-		if (net_ratelimit())
-			netdev_err(dev, "RX parity error\n");
+		net_ratelimited_function(netdev_err, dev, "RX parity error\n");
 		sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR);
 	}
 
 	if (status & Y2_IS_TCP_TXA1) {
-		if (net_ratelimit())
-			netdev_err(dev, "TCP segmentation error\n");
+		net_ratelimited_function(netdev_err, dev, "TCP segmentation error\n");
 		sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP);
 	}
 }
@@ -2880,8 +2872,7 @@ static void sky2_hw_intr(struct sky2_hw *hw)
 
 		sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
 		pci_err = sky2_pci_read16(hw, PCI_STATUS);
-		if (net_ratelimit())
-			dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
+		net_ratelimited_function(dev_err, &pdev->dev, "PCI hardware error (0x%x)\n",
 			        pci_err);
 
 		sky2_pci_write16(hw, PCI_STATUS,
@@ -2897,8 +2888,7 @@ static void sky2_hw_intr(struct sky2_hw *hw)
 		err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
 		sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
 			     0xfffffffful);
-		if (net_ratelimit())
-			dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
+		net_ratelimited_function(dev_err, &pdev->dev, "PCI Express error (0x%x)\n", err);
 
 		sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
 		sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
@@ -3017,8 +3007,8 @@ static void sky2_watchdog(unsigned long arg)
 /* Hardware/software error handling */
 static void sky2_err_intr(struct sky2_hw *hw, u32 status)
 {
-	if (net_ratelimit())
-		dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status);
+	net_ratelimited_function(dev_warn, &hw->pdev->dev,
+		"error interrupt status=%#x\n", status);
 
 	if (status & Y2_IS_HW_ERR)
 		sky2_hw_intr(hw);
diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
index 149355b..920ef96 100644
--- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
+++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
@@ -3559,9 +3559,8 @@ myri10ge_check_slice(struct myri10ge_slice_state *ss, int *reset_needed,
 	    ss->watchdog_tx_req != ss->watchdog_tx_done) {
 		/* nic seems like it might be stuck.. */
 		if (rx_pause_cnt != mgp->watchdog_pause) {
-			if (net_ratelimit())
-				netdev_warn(mgp->dev, "slice %d: TX paused, "
-					    "check link partner\n", slice);
+			net_ratelimited_function(netdev_warn, mgp->dev,
+				"slice %d: TX paused, check link partner\n", slice);
 		} else {
 			netdev_warn(mgp->dev,
 				    "slice %d: TX stuck %d %d %d %d %d %d\n",
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 3397cee..5e0ee96 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -1496,8 +1496,7 @@ static void __rtl8169_check_link_status(struct net_device *dev,
 		if (pm)
 			pm_request_resume(&tp->pci_dev->dev);
 		netif_carrier_on(dev);
-		if (net_ratelimit())
-			netif_info(tp, ifup, dev, "link up\n");
+		net_ratelimited_function(netif_info, tp, ifup, dev, "link up\n");
 	} else {
 		netif_carrier_off(dev);
 		netif_info(tp, ifdown, dev, "link down\n");
@@ -5732,8 +5731,8 @@ static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
 	mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz,
 				 DMA_FROM_DEVICE);
 	if (unlikely(dma_mapping_error(d, mapping))) {
-		if (net_ratelimit())
-			netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n");
+		net_ratelimited_function(netif_err,
+			tp, drv, tp->dev, "Failed to map RX DMA!\n");
 		goto err_out;
 	}
 
@@ -5895,8 +5894,7 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
 		addr = skb_frag_address(frag);
 		mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE);
 		if (unlikely(dma_mapping_error(d, mapping))) {
-			if (net_ratelimit())
-				netif_err(tp, drv, tp->dev,
+			net_ratelimited_function(netif_err, tp, drv, tp->dev,
 					  "Failed to map TX fragments DMA!\n");
 			goto err_out;
 		}
@@ -5996,8 +5994,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
 	len = skb_headlen(skb);
 	mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE);
 	if (unlikely(dma_mapping_error(d, mapping))) {
-		if (net_ratelimit())
-			netif_err(tp, drv, dev, "Failed to map TX DMA!\n");
+		net_ratelimited_function(netif_err, tp, drv, dev, "Failed to map TX DMA!\n");
 		goto err_dma_0;
 	}
 
diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c
index 4a59672..b53f16d 100644
--- a/drivers/net/ethernet/sfc/rx.c
+++ b/drivers/net/ethernet/sfc/rx.c
@@ -397,19 +397,17 @@ static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue,
 	rx_buf->flags |= EFX_RX_PKT_DISCARD;
 
 	if ((len > rx_buf->len) && EFX_WORKAROUND_8071(efx)) {
-		if (net_ratelimit())
-			netif_err(efx, rx_err, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, rx_err, efx->net_dev,
 				  " RX queue %d seriously overlength "
 				  "RX event (0x%x > 0x%x+0x%x). Leaking\n",
 				  efx_rx_queue_index(rx_queue), len, max_len,
 				  efx->type->rx_buffer_padding);
 		efx_schedule_reset(efx, RESET_TYPE_RX_RECOVERY);
 	} else {
-		if (net_ratelimit())
-			netif_err(efx, rx_err, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, rx_err, efx->net_dev,
 				  " RX queue %d overlength RX event "
 				  "(0x%x > 0x%x)\n",
-				  efx_rx_queue_index(rx_queue), len, max_len);
+		efx_rx_queue_index(rx_queue), len, max_len);
 	}
 
 	efx_rx_queue_channel(rx_queue)->n_rx_overlength++;
diff --git a/drivers/net/ethernet/sfc/siena_sriov.c b/drivers/net/ethernet/sfc/siena_sriov.c
index 0c38f92..71ec42d 100644
--- a/drivers/net/ethernet/sfc/siena_sriov.c
+++ b/drivers/net/ethernet/sfc/siena_sriov.c
@@ -532,8 +532,7 @@ static int efx_vfdi_init_evq(struct efx_vf *vf)
 
 	if (bad_vf_index(efx, vf_evq) ||
 	    bad_buf_count(buf_count, EFX_MAX_VF_EVQ_SIZE)) {
-		if (net_ratelimit())
-			netif_err(efx, hw, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 				  "ERROR: Invalid INIT_EVQ from %s: evq %d bufs %d\n",
 				  vf->pci_name, vf_evq, buf_count);
 		return VFDI_RC_EINVAL;
@@ -575,8 +574,7 @@ static int efx_vfdi_init_rxq(struct efx_vf *vf)
 	if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_rxq) ||
 	    vf_rxq >= VF_MAX_RX_QUEUES ||
 	    bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {
-		if (net_ratelimit())
-			netif_err(efx, hw, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 				  "ERROR: Invalid INIT_RXQ from %s: rxq %d evq %d "
 				  "buf_count %d\n", vf->pci_name, vf_rxq,
 				  vf_evq, buf_count);
@@ -616,8 +614,7 @@ static int efx_vfdi_init_txq(struct efx_vf *vf)
 	if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_txq) ||
 	    vf_txq >= vf_max_tx_channels ||
 	    bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {
-		if (net_ratelimit())
-			netif_err(efx, hw, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 				  "ERROR: Invalid INIT_TXQ from %s: txq %d evq %d "
 				  "buf_count %d\n", vf->pci_name, vf_txq,
 				  vf_evq, buf_count);
@@ -759,8 +756,7 @@ static int efx_vfdi_insert_filter(struct efx_vf *vf)
 	unsigned flags;
 
 	if (bad_vf_index(efx, vf_rxq) || vf->rx_filtering) {
-		if (net_ratelimit())
-			netif_err(efx, hw, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 				  "ERROR: Invalid INSERT_FILTER from %s: rxq %d "
 				  "flags 0x%x\n", vf->pci_name, vf_rxq,
 				  req->u.mac_filter.flags);
@@ -802,8 +798,7 @@ static int efx_vfdi_set_status_page(struct efx_vf *vf)
 		/ sizeof(req->u.set_status_page.peer_page_addr[0]);
 
 	if (!req->u.set_status_page.dma_addr || page_count > max_page_count) {
-		if (net_ratelimit())
-			netif_err(efx, hw, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 				  "ERROR: Invalid SET_STATUS_PAGE from %s\n",
 				  vf->pci_name);
 		return VFDI_RC_EINVAL;
@@ -875,8 +870,7 @@ static void efx_sriov_vfdi(struct work_struct *work)
 	rc = efx_sriov_memcpy(efx, copy, 1);
 	if (rc) {
 		/* If we can't get the request, we can't reply to the caller */
-		if (net_ratelimit())
-			netif_err(efx, hw, efx->net_dev,
+		net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 				  "ERROR: Unable to fetch VFDI request from %s rc %d\n",
 				  vf->pci_name, -rc);
 		vf->busy = false;
@@ -963,8 +957,7 @@ static void efx_sriov_reset_vf(struct efx_vf *vf, struct efx_buffer *buffer)
 		}
 		rc = efx_sriov_memcpy(efx, copy_req, count);
 		if (rc) {
-			if (net_ratelimit())
-				netif_err(efx, hw, efx->net_dev,
+			net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 					  "ERROR: Unable to notify %s of reset"
 					  ": %d\n", vf->pci_name, -rc);
 			break;
@@ -1420,8 +1413,7 @@ void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event)
 	}
 
 error:
-	if (net_ratelimit())
-		netif_err(efx, hw, efx->net_dev,
+	net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 			  "ERROR: Screaming VFDI request from %s\n",
 			  vf->pci_name);
 	/* Reset the request and sequence number */
@@ -1509,8 +1501,7 @@ void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq)
 	if (map_vi_index(efx, dmaq, &vf, &rel))
 		return;
 
-	if (net_ratelimit())
-		netif_err(efx, hw, efx->net_dev,
+	net_ratelimited_function(netif_err, efx, hw, efx->net_dev,
 			  "VF %d DMA Q %d reports descriptor fetch error.\n",
 			  vf->index, rel);
 	queue_work(vfdi_workqueue, &vf->reset_work);
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 67df09e..caab0a9 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1408,10 +1408,8 @@ static int emac_poll(struct napi_struct *napi, int budget)
 		if (cause) {
 			ch = ((status & EMAC_MACSTATUS_TXERRCH_MASK) >>
 			      EMAC_MACSTATUS_TXERRCH_SHIFT);
-			if (net_ratelimit()) {
-				dev_err(emac_dev, "TX Host error %s on ch=%d\n",
+			net_ratelimited_function(dev_err, emac_dev, "TX Host error %s on ch=%d\n",
 					&emac_txhost_errcodes[cause][0], ch);
-			}
 		}
 		cause = ((status & EMAC_MACSTATUS_RXERRCODE_MASK) >>
 			 EMAC_MACSTATUS_RXERRCODE_SHIFT);
diff --git a/drivers/net/ethernet/tundra/tsi108_eth.c b/drivers/net/ethernet/tundra/tsi108_eth.c
index c4dbf98..467d76d 100644
--- a/drivers/net/ethernet/tundra/tsi108_eth.c
+++ b/drivers/net/ethernet/tundra/tsi108_eth.c
@@ -669,10 +669,7 @@ static int tsi108_send_packet(struct sk_buff * skb, struct net_device *dev)
 
 	if (data->txfree < MAX_SKB_FRAGS + 1) {
 		netif_stop_queue(dev);
-
-		if (net_ratelimit())
-			printk(KERN_ERR "%s: Transmit with full tx ring!\n",
-			       dev->name);
+		net_err_ratelimited("%s: Transmit with full tx ring!\n", dev->name);
 		return NETDEV_TX_BUSY;
 	}
 
@@ -869,9 +866,7 @@ static int tsi108_poll(struct napi_struct *napi, int budget)
 		TSI_WRITE(TSI108_EC_RXERR, err);
 
 		if (err) {
-			if (net_ratelimit())
-				printk(KERN_DEBUG "%s: RX error %x\n",
-				       dev->name, err);
+			net_dbg_ratelimited("%s: RX error %x\n", dev->name, err);
 
 			if (!(TSI_READ(TSI108_EC_RXSTAT) &
 			      TSI108_EC_RXSTAT_QUEUE0))
@@ -1024,8 +1019,7 @@ static irqreturn_t tsi108_irq(int irq, void *dev_id)
 		tsi108_rx_int(dev);
 
 	if (stat & TSI108_INT_SFN) {
-		if (net_ratelimit())
-			printk(KERN_DEBUG "%s: SFN error\n", dev->name);
+		net_dbg_ratelimited("%s: SFN error\n", dev->name);
 		TSI_WRITE(TSI108_EC_INTSTAT, TSI108_INT_SFN);
 	}
 
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH 06/18] net: wireless: use wrapper functions of net_ratelimit() to simplify code
From: Kefeng Wang @ 2013-10-15 11:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev
In-Reply-To: <1381837514-50660-1-git-send-email-wangkefeng.wang@huawei.com>

Wrapper functions net_ratelimited_function() and net_XXX_ratelimited()
are called to simplify code.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 drivers/net/wireless/adm8211.c                |  5 ++-
 drivers/net/wireless/ath/carl9170/cmd.c       | 15 +++------
 drivers/net/wireless/ath/carl9170/phy.c       |  7 ++---
 drivers/net/wireless/ath/carl9170/rx.c        | 45 ++++++++-------------------
 drivers/net/wireless/ath/carl9170/usb.c       | 12 +++----
 drivers/net/wireless/hostap/hostap_80211_rx.c |  8 ++---
 drivers/net/wireless/hostap/hostap_80211_tx.c | 13 +++-----
 drivers/net/wireless/hostap/hostap_ap.c       |  6 ++--
 drivers/net/wireless/hostap/hostap_hw.c       | 17 +++-------
 drivers/net/wireless/iwlegacy/3945-mac.c      |  4 +--
 drivers/net/wireless/iwlegacy/4965-mac.c      |  6 ++--
 drivers/net/wireless/iwlwifi/pcie/rx.c        |  7 ++---
 drivers/net/wireless/libertas_tf/cmd.c        |  6 ++--
 drivers/net/wireless/mwl8k.c                  |  5 ++-
 drivers/net/wireless/orinoco/hermes.c         |  6 ++--
 drivers/net/wireless/orinoco/main.c           | 16 +++-------
 drivers/net/wireless/orinoco/orinoco_usb.c    |  3 +-
 drivers/net/wireless/p54/p54pci.c             |  6 ++--
 18 files changed, 61 insertions(+), 126 deletions(-)

diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index f9a24e5..2fafb8a 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -374,9 +374,8 @@ static void adm8211_interrupt_rci(struct ieee80211_hw *dev)
 
 		pktlen = status & RDES0_STATUS_FL;
 		if (pktlen > RX_PKT_SIZE) {
-			if (net_ratelimit())
-				wiphy_debug(dev->wiphy, "frame too long (%d)\n",
-					    pktlen);
+			net_ratelimited_function(wiphy_debug, dev->wiphy,
+				"frame too long (%d)\n", pktlen);
 			pktlen = RX_PKT_SIZE;
 		}
 
diff --git a/drivers/net/wireless/ath/carl9170/cmd.c b/drivers/net/wireless/ath/carl9170/cmd.c
index 39a6387..3f13398 100644
--- a/drivers/net/wireless/ath/carl9170/cmd.c
+++ b/drivers/net/wireless/ath/carl9170/cmd.c
@@ -50,12 +50,9 @@ int carl9170_write_reg(struct ar9170 *ar, const u32 reg, const u32 val)
 
 	err = carl9170_exec_cmd(ar, CARL9170_CMD_WREG, sizeof(buf),
 				(u8 *) buf, 0, NULL);
-	if (err) {
-		if (net_ratelimit()) {
-			wiphy_err(ar->hw->wiphy, "writing reg %#x "
-				"(val %#x) failed (%d)\n", reg, val, err);
-		}
-	}
+	if (err)
+		net_ratelimited_function(wiphy_err, ar->hw->wiphy,
+			"writing reg %#x (val %#x) failed (%d)\n", reg, val, err);
 	return err;
 }
 
@@ -77,10 +74,8 @@ int carl9170_read_mreg(struct ar9170 *ar, const int nregs,
 				4 * nregs, (u8 *)offs,
 				4 * nregs, (u8 *)res);
 	if (err) {
-		if (net_ratelimit()) {
-			wiphy_err(ar->hw->wiphy, "reading regs failed (%d)\n",
-				  err);
-		}
+		net_ratelimited_function(wiphy_err, ar->hw->wiphy,
+			"reading regs failed (%d)\n", err);
 		return err;
 	}
 
diff --git a/drivers/net/wireless/ath/carl9170/phy.c b/drivers/net/wireless/ath/carl9170/phy.c
index ab4ee7d..cae9125 100644
--- a/drivers/net/wireless/ath/carl9170/phy.c
+++ b/drivers/net/wireless/ath/carl9170/phy.c
@@ -1715,11 +1715,8 @@ int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
 		err = carl9170_write_reg(ar, AR9170_PHY_REG_HEAVY_CLIP_ENABLE,
 					 0x200 | ar->heavy_clip);
 		if (err) {
-			if (net_ratelimit()) {
-				wiphy_err(ar->hw->wiphy, "failed to set "
-				       "heavy clip\n");
-			}
-
+			net_ratelimited_function(wiphy_err,
+				ar->hw->wiphy, "failed to set heavy clip\n");
 			return err;
 		}
 	}
diff --git a/drivers/net/wireless/ath/carl9170/rx.c b/drivers/net/wireless/ath/carl9170/rx.c
index e935f61..0ad905e 100644
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -343,9 +343,8 @@ static int carl9170_rx_mac_status(struct ar9170 *ar,
 	if (unlikely(error)) {
 		/* TODO: update netdevice's RX dropped/errors statistics */
 
-		if (net_ratelimit())
-			wiphy_dbg(ar->hw->wiphy, "received frame with "
-			       "suspicious error code (%#x).\n", error);
+		net_ratelimited_function(wiphy_dbg, ar->hw->wiphy,
+			"received frame with suspicious error code (%#x).\n", error);
 
 		return -EINVAL;
 	}
@@ -374,11 +373,8 @@ static int carl9170_rx_mac_status(struct ar9170 *ar,
 			status->rate_idx = 3;
 			break;
 		default:
-			if (net_ratelimit()) {
-				wiphy_err(ar->hw->wiphy, "invalid plcp cck "
-				       "rate (%x).\n", head->plcp[0]);
-			}
-
+			net_ratelimited_function(wiphy_err, ar->hw->wiphy,
+				"invalid plcp cck rate (%x).\n", head->plcp[0]);
 			return -EINVAL;
 		}
 		break;
@@ -411,11 +407,8 @@ static int carl9170_rx_mac_status(struct ar9170 *ar,
 			status->rate_idx = 7;
 			break;
 		default:
-			if (net_ratelimit()) {
-				wiphy_err(ar->hw->wiphy, "invalid plcp ofdm "
-					"rate (%x).\n", head->plcp[0]);
-			}
-
+			net_ratelimited_function(wiphy_err, ar->hw->wiphy,
+				"invalid plcp ofdm rate (%x).\n", head->plcp[0]);
 			return -EINVAL;
 		}
 		if (status->band == IEEE80211_BAND_2GHZ)
@@ -742,11 +735,8 @@ static void carl9170_rx_untie_data(struct ar9170 *ar, u8 *buf, int len)
 
 			ar->rx_has_plcp = true;
 		} else {
-			if (net_ratelimit()) {
-				wiphy_err(ar->hw->wiphy, "plcp info "
-					"is clipped.\n");
-			}
-
+			net_ratelimited_function(wiphy_err, ar->hw->wiphy,
+				"plcp info is clipped.\n");
 			goto drop;
 		}
 		break;
@@ -763,11 +753,8 @@ static void carl9170_rx_untie_data(struct ar9170 *ar, u8 *buf, int len)
 			mpdu_len -= sizeof(struct ar9170_rx_phystatus);
 			phy = (void *)(buf + mpdu_len);
 		} else {
-			if (net_ratelimit()) {
-				wiphy_err(ar->hw->wiphy, "frame tail "
-					"is clipped.\n");
-			}
-
+			net_ratelimited_function(wiphy_err, ar->hw->wiphy,
+				"frame tail is clipped.\n");
 			goto drop;
 		}
 
@@ -900,11 +887,8 @@ static void carl9170_rx_stream(struct ar9170 *ar, void *buf, unsigned int len)
 			if (!ar->rx_failover_missing) {
 
 				/* this is not "short read". */
-				if (net_ratelimit()) {
-					wiphy_err(ar->hw->wiphy,
+				net_ratelimited_function(wiphy_err, ar->hw->wiphy,
 						"missing tag!\n");
-				}
-
 				__carl9170_rx(ar, tbuf, tlen);
 				return;
 			}
@@ -973,11 +957,8 @@ static void carl9170_rx_stream(struct ar9170 *ar, void *buf, unsigned int len)
 	}
 
 	if (tlen) {
-		if (net_ratelimit()) {
-			wiphy_err(ar->hw->wiphy, "%d bytes of unprocessed "
-				"data left in rx stream!\n", tlen);
-		}
-
+		net_ratelimited_function(wiphy_err, ar->hw->wiphy,
+			"%d bytes of unprocessed data left in rx stream!\n", tlen);
 		goto err_telluser;
 	}
 
diff --git a/drivers/net/wireless/ath/carl9170/usb.c b/drivers/net/wireless/ath/carl9170/usb.c
index 307bc0d..0369f0f 100644
--- a/drivers/net/wireless/ath/carl9170/usb.c
+++ b/drivers/net/wireless/ath/carl9170/usb.c
@@ -144,10 +144,8 @@ static void carl9170_usb_submit_data_urb(struct ar9170 *ar)
 
 	err = usb_submit_urb(urb, GFP_ATOMIC);
 	if (unlikely(err)) {
-		if (net_ratelimit()) {
-			dev_err(&ar->udev->dev, "tx submit failed (%d)\n",
-				urb->status);
-		}
+		net_ratelimited_function(dev_err, &ar->udev->dev,
+			"tx submit failed (%d)\n", urb->status);
 
 		usb_unanchor_urb(urb);
 		usb_anchor_urb(urb, &ar->tx_err);
@@ -194,10 +192,8 @@ static void carl9170_usb_tx_data_complete(struct urb *urb)
 
 	/* a random transmission error has occurred? */
 	default:
-		if (net_ratelimit()) {
-			dev_err(&ar->udev->dev, "tx failed (%d)\n",
-				urb->status);
-		}
+		net_ratelimited_function(dev_err, &ar->udev->dev,
+			"tx failed (%d)\n", urb->status);
 
 		usb_anchor_urb(urb, &ar->tx_err);
 		break;
diff --git a/drivers/net/wireless/hostap/hostap_80211_rx.c b/drivers/net/wireless/hostap/hostap_80211_rx.c
index d39e3e2..a547d79 100644
--- a/drivers/net/wireless/hostap/hostap_80211_rx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_rx.c
@@ -661,11 +661,9 @@ hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
 
 	if (local->tkip_countermeasures &&
 	    strcmp(crypt->ops->name, "TKIP") == 0) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
+		net_dbg_ratelimited("%s: TKIP countermeasures: dropped "
 			       "received packet from %pM\n",
 			       local->dev->name, hdr->addr2);
-		}
 		return -1;
 	}
 
@@ -995,11 +993,9 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
 
 	if (local->drop_unencrypted && !(fc & IEEE80211_FCTL_PROTECTED) &&
 	    !hostap_is_eapol_frame(local, skb)) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: dropped unencrypted RX data "
+		net_dbg_ratelimited("%s: dropped unencrypted RX data "
 			       "frame from %pM (drop_unencrypted=1)\n",
 			       dev->name, hdr->addr2);
-		}
 		goto rx_dropped;
 	}
 
diff --git a/drivers/net/wireless/hostap/hostap_80211_tx.c b/drivers/net/wireless/hostap/hostap_80211_tx.c
index 344a981..7c8f798 100644
--- a/drivers/net/wireless/hostap/hostap_80211_tx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_tx.c
@@ -330,11 +330,8 @@ static struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
 	if (local->tkip_countermeasures &&
 	    strcmp(crypt->ops->name, "TKIP") == 0) {
 		hdr = (struct ieee80211_hdr *) skb->data;
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
-			       "TX packet to %pM\n",
-			       local->dev->name, hdr->addr1);
-		}
+		net_dbg_ratelimited("%s: TKIP countermeasures: dropped "
+			"TX packet to %pM\n", local->dev->name, hdr->addr1);
 		kfree_skb(skb);
 		return NULL;
 	}
@@ -502,10 +499,8 @@ netdev_tx_t hostap_master_start_xmit(struct sk_buff *skb,
 	} else if (local->drop_unencrypted &&
 		   ieee80211_is_data(hdr->frame_control) &&
 		   meta->ethertype != ETH_P_PAE) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: dropped unencrypted TX data "
-			       "frame (drop_unencrypted=1)\n", dev->name);
-		}
+		net_dbg_ratelimited("%s: dropped unencrypted TX data "
+			"frame (drop_unencrypted=1)\n", dev->name);
 		iface->stats.tx_dropped++;
 		ret = NETDEV_TX_OK;
 		goto fail;
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c
index d6033a8..9320dc7 100644
--- a/drivers/net/wireless/hostap/hostap_ap.c
+++ b/drivers/net/wireless/hostap/hostap_ap.c
@@ -2781,10 +2781,8 @@ ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
 		 * for a unicast frame. In this case, the packet is send to all
 		 * ports of the bridge. Since this is a valid scenario, do not
 		 * print out any errors here. */
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "AP: drop packet to non-associated "
-			       "STA %pM\n", hdr->addr1);
-		}
+		net_dbg_ratelimited("AP: drop packet to non-associatedSTA %pM\n",
+			hdr->addr1);
 #endif
 		local->ap->tx_drop_nonassoc++;
 		ret = AP_TX_DROP;
diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c
index c275dc1..34b7246 100644
--- a/drivers/net/wireless/hostap/hostap_hw.c
+++ b/drivers/net/wireless/hostap/hostap_hw.c
@@ -1820,10 +1820,8 @@ static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
 
 	if ((local->func->card_present && !local->func->card_present(local)) ||
 	    !local->hw_ready || local->hw_downloading || local->pri_only) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -"
-			       " skipping\n", dev->name);
-		}
+		net_dbg_ratelimited("%s: prism2_tx_80211: hw not ready skipping\n",
+			dev->name);
 		goto fail;
 	}
 
@@ -2620,10 +2618,8 @@ static irqreturn_t prism2_interrupt(int irq, void *dev_id)
 	/* Detect early interrupt before driver is fully configured */
 	spin_lock(&local->irq_init_lock);
 	if (!dev->base_addr) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: Interrupt, but dev not configured\n",
-			       dev->name);
-		}
+		net_dbg_ratelimited("%s: Interrupt, but dev not configured\n",
+			dev->name);
 		spin_unlock(&local->irq_init_lock);
 		return IRQ_HANDLED;
 	}
@@ -2632,10 +2628,7 @@ static irqreturn_t prism2_interrupt(int irq, void *dev_id)
 	prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
 
 	if (local->func->card_present && !local->func->card_present(local)) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n",
-			       dev->name);
-		}
+		net_dbg_ratelimited("%s: Interrupt, but dev not OK\n", dev->name);
 		return IRQ_HANDLED;
 	}
 
diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
index 9581d07..920c0b8 100644
--- a/drivers/net/wireless/iwlegacy/3945-mac.c
+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
@@ -1027,8 +1027,8 @@ il3945_rx_allocate(struct il_priv *il, gfp_t priority)
 		/* Alloc a new receive buffer */
 		page = alloc_pages(gfp_mask, il->hw_params.rx_page_order);
 		if (!page) {
-			if (net_ratelimit())
-				D_INFO("Failed to allocate SKB buffer.\n");
+			net_ratelimited_function(D_INFO,
+				"Failed to allocate SKB buffer.\n");
 			if (rxq->free_count <= RX_LOW_WATERMARK &&
 			    net_ratelimit())
 				IL_ERR("Failed to allocate SKB buffer with %0x."
diff --git a/drivers/net/wireless/iwlegacy/4965-mac.c b/drivers/net/wireless/iwlegacy/4965-mac.c
index 5ab50a5..4f8de71 100644
--- a/drivers/net/wireless/iwlegacy/4965-mac.c
+++ b/drivers/net/wireless/iwlegacy/4965-mac.c
@@ -340,9 +340,9 @@ il4965_rx_allocate(struct il_priv *il, gfp_t priority)
 		/* Alloc a new receive buffer */
 		page = alloc_pages(gfp_mask, il->hw_params.rx_page_order);
 		if (!page) {
-			if (net_ratelimit())
-				D_INFO("alloc_pages failed, " "order: %d\n",
-				       il->hw_params.rx_page_order);
+			net_ratelimited_function(D_INFO,
+				"alloc_pages failed, order: %d\n",
+				il->hw_params.rx_page_order);
 
 			if (rxq->free_count <= RX_LOW_WATERMARK &&
 			    net_ratelimit())
diff --git a/drivers/net/wireless/iwlwifi/pcie/rx.c b/drivers/net/wireless/iwlwifi/pcie/rx.c
index 3f237b4..022f612 100644
--- a/drivers/net/wireless/iwlwifi/pcie/rx.c
+++ b/drivers/net/wireless/iwlwifi/pcie/rx.c
@@ -293,10 +293,9 @@ static void iwl_pcie_rxq_alloc_rbs(struct iwl_trans *trans, gfp_t priority)
 		/* Alloc a new receive buffer */
 		page = alloc_pages(gfp_mask, trans_pcie->rx_page_order);
 		if (!page) {
-			if (net_ratelimit())
-				IWL_DEBUG_INFO(trans, "alloc_pages failed, "
-					   "order: %d\n",
-					   trans_pcie->rx_page_order);
+			net_ratelimited_function(IWL_DEBUG_INFO, trans,
+				"alloc_pages failed, order: %d\n",
+				trans_pcie->rx_page_order);
 
 			if ((rxq->free_count <= RX_LOW_WATERMARK) &&
 			    net_ratelimit())
diff --git a/drivers/net/wireless/libertas_tf/cmd.c b/drivers/net/wireless/libertas_tf/cmd.c
index 909ac36..806f750 100644
--- a/drivers/net/wireless/libertas_tf/cmd.c
+++ b/drivers/net/wireless/libertas_tf/cmd.c
@@ -737,10 +737,8 @@ int lbtf_process_rx_command(struct lbtf_private *priv)
 	respcmd = le16_to_cpu(resp->command);
 	result = le16_to_cpu(resp->result);
 
-	if (net_ratelimit())
-		pr_info("libertastf: cmd response 0x%04x, seq %d, size %d\n",
-			respcmd, le16_to_cpu(resp->seqnum),
-			le16_to_cpu(resp->size));
+	net_info_ratelimited("libertastf: cmd response 0x%04x, seq %d, size %d\n",
+		respcmd, le16_to_cpu(resp->seqnum), le16_to_cpu(resp->size));
 
 	if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
 		spin_unlock_irqrestore(&priv->driver_lock, flags);
diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index a3707fd..fe19424 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -5060,9 +5060,8 @@ mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
 	 * interface is active.
 	 */
 	if (!list_empty(&priv->vif_list)) {
-		if (net_ratelimit())
-			wiphy_info(hw->wiphy,
-				   "not enabling sniffer mode because STA interface is active\n");
+		net_ratelimited_function(wiphy_info, hw->wiphy,
+			"not enabling sniffer mode because STA interface is active\n");
 		return 0;
 	}
 
diff --git a/drivers/net/wireless/orinoco/hermes.c b/drivers/net/wireless/orinoco/hermes.c
index 75c15bc..e4ff42f 100644
--- a/drivers/net/wireless/orinoco/hermes.c
+++ b/drivers/net/wireless/orinoco/hermes.c
@@ -261,14 +261,12 @@ static int hermes_docmd_wait(struct hermes *hw, u16 cmd, u16 parm0,
 	err = hermes_issue_cmd(hw, cmd, parm0, 0, 0);
 	if (err) {
 		if (!hermes_present(hw)) {
-			if (net_ratelimit())
-				printk(KERN_WARNING "hermes @ %p: "
+			net_warn_ratelimited("hermes @ %p: "
 				       "Card removed while issuing command "
 				       "0x%04x.\n", hw->iobase, cmd);
 			err = -ENODEV;
 		} else
-			if (net_ratelimit())
-				printk(KERN_ERR "hermes @ %p: "
+			net_err_ratelimited("hermes @ %p: "
 				       "Error %d issuing command 0x%04x.\n",
 				       hw->iobase, err, cmd);
 		goto out;
diff --git a/drivers/net/wireless/orinoco/main.c b/drivers/net/wireless/orinoco/main.c
index 38ec8d1..22f3a6a 100644
--- a/drivers/net/wireless/orinoco/main.c
+++ b/drivers/net/wireless/orinoco/main.c
@@ -394,9 +394,7 @@ int orinoco_process_xmit_skb(struct sk_buff *skb,
 		int len = skb->len + sizeof(encaps_hdr) - (2 * ETH_ALEN);
 
 		if (skb_headroom(skb) < ENCAPS_OVERHEAD) {
-			if (net_ratelimit())
-				printk(KERN_ERR
-				       "%s: Not enough headroom for 802.2 headers %d\n",
+			net_err_ratelimited("%s: Not enough headroom for 802.2 headers %d\n",
 				       dev->name, skb_headroom(skb));
 			return -ENOMEM;
 		}
@@ -495,8 +493,7 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
 		err = hw->ops->bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
 					  txfid, 0);
 		if (err) {
-			if (net_ratelimit())
-				printk(KERN_ERR "%s: Error %d writing Tx "
+			net_err_ratelimited("%s: Error %d writing Tx "
 				       "descriptor to BAP\n", dev->name, err);
 			goto busy;
 		}
@@ -509,8 +506,7 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
 		err = hw->ops->bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
 					  txfid, 0);
 		if (err) {
-			if (net_ratelimit())
-				printk(KERN_ERR "%s: Error %d writing Tx "
+			net_err_ratelimited("%s: Error %d writing Tx "
 				       "descriptor to BAP\n", dev->name, err);
 			goto busy;
 		}
@@ -554,8 +550,7 @@ static netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
 				txfid, NULL);
 	if (err) {
 		netif_start_queue(dev);
-		if (net_ratelimit())
-			printk(KERN_ERR "%s: Error %d transmitting packet\n",
+		net_err_ratelimited("%s: Error %d transmitting packet\n",
 				dev->name, err);
 		goto busy;
 	}
@@ -1622,8 +1617,7 @@ EXPORT_SYMBOL(__orinoco_ev_info);
 
 static void __orinoco_ev_infdrop(struct net_device *dev, struct hermes *hw)
 {
-	if (net_ratelimit())
-		printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
+	net_dbg_ratelimited("%s: Information frame lost.\n", dev->name);
 }
 
 /********************************************************************/
diff --git a/drivers/net/wireless/orinoco/orinoco_usb.c b/drivers/net/wireless/orinoco/orinoco_usb.c
index bdfe637..65a43d6 100644
--- a/drivers/net/wireless/orinoco/orinoco_usb.c
+++ b/drivers/net/wireless/orinoco/orinoco_usb.c
@@ -1286,8 +1286,7 @@ static netdev_tx_t ezusb_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	if (err) {
 		netif_start_queue(dev);
-		if (net_ratelimit())
-			printk(KERN_ERR "%s: Error %d transmitting packet\n",
+		net_err_ratelimited("%s: Error %d transmitting packet\n",
 				dev->name, err);
 		goto busy;
 	}
diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c
index 57e3af8..1609084 100644
--- a/drivers/net/wireless/p54/p54pci.c
+++ b/drivers/net/wireless/p54/p54pci.c
@@ -212,10 +212,8 @@ static void p54p_check_rx_ring(struct ieee80211_hw *dev, u32 *index,
 		}
 
 		if (unlikely(len > priv->common.rx_mtu)) {
-			if (net_ratelimit())
-				dev_err(&priv->pdev->dev, "rx'd frame size "
-					"exceeds length threshold.\n");
-
+			net_ratelimited_function(dev_err, &priv->pdev->dev,
+				"rx'd frame size exceeds length threshold.\n");
 			len = priv->common.rx_mtu;
 		}
 		dma_addr = le32_to_cpu(desc->host_addr);
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH 05/18] rt18192u: use wrapper functions of net_ratelimit() to simplify code
From: Kefeng Wang @ 2013-10-15 11:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev
In-Reply-To: <1381837514-50660-1-git-send-email-wangkefeng.wang@huawei.com>

net_XXX_ratelimited() is called to simplify code.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 .../rtl8192u/ieee80211/ieee80211_crypt_ccmp.c      | 17 ++++-------------
 .../rtl8192u/ieee80211/ieee80211_crypt_tkip.c      | 22 +++++-----------------
 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c  |  7 ++-----
 drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c  |  4 +---
 4 files changed, 12 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
index f2b1677..534f0a4 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
@@ -284,10 +284,8 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos = skb->data + hdr_len;
 	keyidx = pos[3];
 	if (!(keyidx & (1 << 5))) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "CCMP: received packet without ExtIV"
+		net_dbg_ratelimited("CCMP: received packet without ExtIV"
 			       " flag from %pM\n", hdr->addr2);
-		}
 		key->dot11RSNAStatsCCMPFormatErrors++;
 		return -2;
 	}
@@ -298,11 +296,9 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		return -6;
 	}
 	if (!key->key_set) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "CCMP: received packet from %pM"
+		net_dbg_ratelimited("CCMP: received packet from %pM"
 			       " with keyid=%d that does not have a configured"
 			       " key\n", hdr->addr2, keyidx);
-		}
 		return -3;
 	}
 
@@ -315,11 +311,9 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos += 8;
 
 	if (memcmp(pn, key->rx_pn, CCMP_PN_LEN) <= 0) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "CCMP: replay detected: STA=%pM"
+		net_dbg_ratelimited("CCMP: replay detected: STA=%pM"
 			       " previous PN %pm received PN %pm\n",
 			       hdr->addr2, key->rx_pn, pn);
-		}
 		key->dot11RSNAStatsCCMPReplays++;
 		return -4;
 	}
@@ -353,10 +347,7 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		}
 
 		if (memcmp(mic, a, CCMP_MIC_LEN) != 0) {
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG "CCMP: decrypt failed: STA="
-				"%pM\n", hdr->addr2);
-			}
+			net_dbg_ratelimited("CCMP: decrypt failed: STA=%pM\n", hdr->addr2);
 			key->dot11RSNAStatsCCMPDecryptErrors++;
 			return -5;
 		}
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
index 93121b4..7bb5a96 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
@@ -406,10 +406,8 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos = skb->data + hdr_len;
 	keyidx = pos[3];
 	if (!(keyidx & (1 << 5))) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: received packet without ExtIV"
+		net_dbg_ratelimited("TKIP: received packet without ExtIV"
 			       " flag from %pM\n", hdr->addr2);
-		}
 		return -2;
 	}
 	keyidx >>= 6;
@@ -419,11 +417,9 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		return -6;
 	}
 	if (!tkey->key_set) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: received packet from %pM"
+		net_dbg_ratelimited("TKIP: received packet from %pM"
 			       " with keyid=%d that does not have a configured"
 			       " key\n", hdr->addr2, keyidx);
-		}
 		return -3;
 	}
 	iv16 = (pos[0] << 8) | pos[2];
@@ -434,12 +430,10 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	{
 		if (iv32 < tkey->rx_iv32 ||
 		(iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) {
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG "TKIP: replay detected: STA=%pM"
+			net_dbg_ratelimited("TKIP: replay detected: STA=%pM"
 				" previous TSC %08x%04x received TSC "
 				"%08x%04x\n", hdr->addr2,
 				tkey->rx_iv32, tkey->rx_iv16, iv32, iv16);
-			}
 			tkey->dot11RSNAStatsTKIPReplays++;
 			return -4;
 		}
@@ -456,11 +450,8 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		sg_init_one(&sg, pos, plen+4);
 
 		if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG ": TKIP: failed to decrypt "
-						"received packet from %pM\n",
+			net_dbg_ratelimited("TKIP: failed to decrypt received packet from %pM\n",
 						hdr->addr2);
-			}
 			return -7;
 		}
 
@@ -476,10 +467,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 				* it needs to be recalculated for the next packet. */
 				tkey->rx_phase1_done = 0;
 			}
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG "TKIP: ICV error detected: STA="
-				"%pM\n", hdr->addr2);
-			}
+			net_dbg_ratelimited("TKIP: ICV error detected: STA=%pM\n", hdr->addr2);
 			tkey->dot11RSNAStatsTKIPICVErrors++;
 			return -5;
 		}
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index 59900bf..5e6c1eb 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -355,11 +355,9 @@ ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
 	if (ieee->tkip_countermeasures &&
 	    strcmp(crypt->ops->name, "TKIP") == 0) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
+		net_dbg_ratelimited("%s: TKIP countermeasures: dropped "
 			       "received packet from %pM\n",
 			       ieee->dev->name, hdr->addr2);
-		}
 		return -1;
 	}
 #endif
@@ -946,8 +944,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
 
 	if(HTCCheck(ieee, skb->data))
 	{
-		if(net_ratelimit())
-		printk("find HTCControl\n");
+		net_info_ratelimited("find HTCControl\n");
 		hdrlen += 4;
 		rx_stats->bContainHTC = 1;
 	}
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index a7bcc64f..55c24d7 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -197,11 +197,9 @@ int ieee80211_encrypt_fragment(
 	if (ieee->tkip_countermeasures &&
 	    crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) {
 		header = (struct ieee80211_hdr *) frag->data;
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
+		net_dbg_ratelimited("%s: TKIP countermeasures: dropped "
 			       "TX packet to %pM\n",
 			       ieee->dev->name, header->addr1);
-		}
 		return -1;
 	}
 #endif
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH 04/18] rt18192e: use wrapper functions of net_ratelimit() to simplify code
From: Kefeng Wang @ 2013-10-15 11:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev
In-Reply-To: <1381837514-50660-1-git-send-email-wangkefeng.wang@huawei.com>

Wrapper functions net_ratelimited_function() and net_XXX_ratelimited()
are called to simplify code.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 drivers/staging/rtl8192e/rtllib_crypt_ccmp.c | 13 +++----------
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 21 +++++----------------
 drivers/staging/rtl8192e/rtllib_rx.c         |  6 ++----
 3 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c b/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c
index e51cb49..0d089c1 100644
--- a/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c
+++ b/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c
@@ -275,10 +275,8 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos = skb->data + hdr_len;
 	keyidx = pos[3];
 	if (!(keyidx & (1 << 5))) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "CCMP: received packet without ExtIV"
+		net_dbg_ratelimited("CCMP: received packet without ExtIV"
 			       " flag from %pM\n", hdr->addr2);
-		}
 		key->dot11RSNAStatsCCMPFormatErrors++;
 		return -2;
 	}
@@ -289,11 +287,9 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		return -6;
 	}
 	if (!key->key_set) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "CCMP: received packet from %pM"
+		net_dbg_ratelimited("CCMP: received packet from %pM"
 			       " with keyid=%d that does not have a configured"
 			       " key\n", hdr->addr2, keyidx);
-		}
 		return -3;
 	}
 
@@ -338,10 +334,7 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		}
 
 		if (memcmp(mic, a, CCMP_MIC_LEN) != 0) {
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG "CCMP: decrypt failed: STA="
-				" %pM\n", hdr->addr2);
-			}
+			net_dbg_ratelimited("CCMP: decrypt failed: STA= %pM\n", hdr->addr2);
 			key->dot11RSNAStatsCCMPDecryptErrors++;
 			return -5;
 		}
diff --git a/drivers/staging/rtl8192e/rtllib_crypt_tkip.c b/drivers/staging/rtl8192e/rtllib_crypt_tkip.c
index 5cfd73b..c1f7683 100644
--- a/drivers/staging/rtl8192e/rtllib_crypt_tkip.c
+++ b/drivers/staging/rtl8192e/rtllib_crypt_tkip.c
@@ -396,10 +396,8 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos = skb->data + hdr_len;
 	keyidx = pos[3];
 	if (!(keyidx & (1 << 5))) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: received packet without ExtIV"
+		net_dbg_ratelimited("TKIP: received packet without ExtIV"
 			       " flag from %pM\n", hdr->addr2);
-		}
 		return -2;
 	}
 	keyidx >>= 6;
@@ -409,11 +407,9 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		return -6;
 	}
 	if (!tkey->key_set) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: received packet from %pM"
+		net_dbg_ratelimited("TKIP: received packet from %pM"
 			       " with keyid=%d that does not have a configured"
 			       " key\n", hdr->addr2, keyidx);
-		}
 		return -3;
 	}
 	iv16 = (pos[0] << 8) | pos[2];
@@ -424,12 +420,10 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		if ((iv32 < tkey->rx_iv32 ||
 		    (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) &&
 		    tkey->initialized) {
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG "TKIP: replay detected: STA="
+			net_dbg_ratelimited("TKIP: replay detected: STA="
 				       " %pM previous TSC %08x%04x received "
 				      "TSC %08x%04x\n",hdr->addr2,
 				      tkey->rx_iv32, tkey->rx_iv16, iv32, iv16);
-			}
 			tkey->dot11RSNAStatsTKIPReplays++;
 			return -4;
 		}
@@ -448,11 +442,9 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
 		crypto_blkcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
 		if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG ": TKIP: failed to decrypt "
+			net_dbg_ratelimited(": TKIP: failed to decrypt "
 				       "received packet from %pM\n",
 				       hdr->addr2);
-			}
 			return -7;
 		}
 
@@ -469,10 +461,7 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 				 * next packet. */
 				tkey->rx_phase1_done = 0;
 			}
-			if (net_ratelimit()) {
-				printk(KERN_DEBUG "TKIP: ICV error detected: STA="
-				" %pM\n", hdr->addr2);
-			}
+			net_dbg_ratelimited("TKIP: ICV error detected: STA= %pM\n", hdr->addr2);
 			tkey->dot11RSNAStatsTKIPICVErrors++;
 			return -5;
 		}
diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index 8aeaed5..4335611 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -870,8 +870,7 @@ static size_t rtllib_rx_get_hdrlen(struct rtllib_device *ieee,
 
 	hdrlen = rtllib_get_hdrlen(fc);
 	if (HTCCheck(ieee, skb->data)) {
-		if (net_ratelimit())
-			printk(KERN_INFO "%s: find HTCControl!\n", __func__);
+		net_info_ratelimited("%s: find HTCControl!\n", __func__);
 		hdrlen += 4;
 		rx_stats->bContainHTC = 1;
 	}
@@ -1439,8 +1438,7 @@ static int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb,
 	}
 
 	if (HTCCheck(ieee, skb->data)) {
-		if (net_ratelimit())
-			printk(KERN_INFO "%s: Find HTCControl!\n", __func__);
+		net_info_ratelimited("%s: Find HTCControl!\n", __func__);
 		hdrlen += 4;
 	}
 
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH 03/18] rt18187se: use wrapper functions of net_ratelimit() to simplify code
From: Kefeng Wang @ 2013-10-15 11:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev
In-Reply-To: <1381837514-50660-1-git-send-email-wangkefeng.wang@huawei.com>

Wrapper functions net_ratelimited_function() and net_XXX_ratelimited()
are called to simplify code.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 .../rtl8187se/ieee80211/ieee80211_crypt_ccmp.c     | 16 ++++---------
 .../rtl8187se/ieee80211/ieee80211_crypt_tkip.c     | 27 ++++++----------------
 drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c |  4 +---
 drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c |  7 ++----
 4 files changed, 14 insertions(+), 40 deletions(-)

diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_ccmp.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_ccmp.c
index f5949e8..be6c5a1 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_ccmp.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_ccmp.c
@@ -282,10 +282,8 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos = skb->data + hdr_len;
 	keyidx = pos[3];
 	if (!(keyidx & (1 << 5))) {
-		if (net_ratelimit()) {
-			pr_debug("received packet without ExtIV flag from %pM\n",
+		net_dbg_ratelimited("received packet without ExtIV flag from %pM\n",
 				 hdr->addr2);
-		}
 		key->dot11RSNAStatsCCMPFormatErrors++;
 		return -2;
 	}
@@ -296,10 +294,8 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		return -6;
 	}
 	if (!key->key_set) {
-		if (net_ratelimit()) {
-			pr_debug("received packet from %pM with keyid=%d that does not have a configured key\n",
+		net_dbg_ratelimited("received packet from %pM with keyid=%d that does not have a configured key\n",
 				 hdr->addr2, keyidx);
-		}
 		return -3;
 	}
 
@@ -312,10 +308,8 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos += 8;
 
 	if (memcmp(pn, key->rx_pn, CCMP_PN_LEN) <= 0) {
-		if (net_ratelimit()) {
-			pr_debug("replay detected: STA=%pM previous PN %pm received PN %pm\n",
+		net_dbg_ratelimited("replay detected: STA=%pM previous PN %pm received PN %pm\n",
 				 hdr->addr2, key->rx_pn, pn);
-		}
 		key->dot11RSNAStatsCCMPReplays++;
 		return -4;
 	}
@@ -340,9 +334,7 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	}
 
 	if (memcmp(mic, a, CCMP_MIC_LEN) != 0) {
-		if (net_ratelimit())
-			pr_debug("decrypt failed: STA=%pM\n", hdr->addr2);
-
+		net_dbg_ratelimited("decrypt failed: STA=%pM\n", hdr->addr2);
 		key->dot11RSNAStatsCCMPDecryptErrors++;
 		return -5;
 	}
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
index da24e43..03e1961 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
@@ -381,10 +381,8 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	pos = skb->data + hdr_len;
 	keyidx = pos[3];
 	if (!(keyidx & (1 << 5))) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: received packet without ExtIV"
+		net_dbg_ratelimited("TKIP: received packet without ExtIV"
 			       " flag from %pM\n", hdr->addr2);
-		}
 		return -2;
 	}
 	keyidx >>= 6;
@@ -394,11 +392,9 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		return -6;
 	}
 	if (!tkey->key_set) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: received packet from %pM"
+		net_dbg_ratelimited("TKIP: received packet from %pM"
 			       " with keyid=%d that does not have a configured"
 			       " key\n", hdr->addr2, keyidx);
-		}
 		return -3;
 	}
 	iv16 = (pos[0] << 8) | pos[2];
@@ -407,12 +403,9 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
 	if (iv32 < tkey->rx_iv32 ||
 	    (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: replay detected: STA=%pM"
-			       " previous TSC %08x%04x received TSC "
-			       "%08x%04x\n", hdr->addr2,
-			       tkey->rx_iv32, tkey->rx_iv16, iv32, iv16);
-		}
+		net_dbg_ratelimited("TKIP: replay detected: STA=%pM"
+			" previous TSC %08x%04x received TSC %08x%04x\n",
+			hdr->addr2, tkey->rx_iv32, tkey->rx_iv16, iv32, iv16);
 		tkey->dot11RSNAStatsTKIPReplays++;
 		return -4;
 	}
@@ -427,11 +420,8 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	crypto_blkcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
 	sg_init_one(&sg, pos, plen + 4);
 	if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG ": TKIP: failed to decrypt "
-			       "received packet from %pM\n",
+		net_dbg_ratelimited(": TKIP: failed to decrypt received packet from %pM\n",
 			       hdr->addr2);
-		}
 		return -7;
 	}
 
@@ -446,10 +436,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 			 * it needs to be recalculated for the next packet. */
 			tkey->rx_phase1_done = 0;
 		}
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "TKIP: ICV error detected: STA="
-			       "%pM\n", hdr->addr2);
-		}
+		net_dbg_ratelimited("TKIP: ICV error detected: STA=%pM\n", hdr->addr2);
 		tkey->dot11RSNAStatsTKIPICVErrors++;
 		return -5;
 	}
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c
index 10b2210..fa125f2 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c
@@ -307,11 +307,9 @@ ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
 	if (ieee->tkip_countermeasures &&
 	    strcmp(crypt->ops->name, "TKIP") == 0) {
-		if (net_ratelimit()) {
-			netdev_dbg(ieee->dev,
+		net_ratelimited_function(netdev_dbg, ieee->dev,
 				   "TKIP countermeasures: dropped received packet from %pM\n",
 				   ieee->dev->name, hdr->addr2);
-		}
 		return -1;
 	}
 #endif
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
index b346653..366b1df3 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
@@ -196,11 +196,8 @@ int ieee80211_encrypt_fragment(
 	if (ieee->tkip_countermeasures &&
 	    crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) {
 		header = (struct ieee80211_hdr_4addr *)frag->data;
-		if (net_ratelimit()) {
-			printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
-			       "TX packet to %pM\n",
-			       ieee->dev->name, header->addr1);
-		}
+		net_dbg_ratelimited("%s: TKIP countermeasures: dropped "
+			"TX packet to %pM\n", ieee->dev->name, header->addr1);
 		return -1;
 	}
 #endif
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH 02/18] net: use wrapper functions of net_ratelimit() to simplify code
From: Kefeng Wang @ 2013-10-15 11:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev
In-Reply-To: <1381837514-50660-1-git-send-email-wangkefeng.wang@huawei.com>

Wrapper functions net_ratelimited_function() and net_XXX_ratelimited()
are called to simplify code.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 net/bridge/br_fdb.c                   |  6 ++----
 net/bridge/br_multicast.c             | 13 ++++---------
 net/bridge/br_stp_bpdu.c              | 11 ++++-------
 net/mac80211/rx.c                     |  6 ++----
 net/netfilter/ipset/ip_set_hash_gen.h |  3 +--
 5 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index ffd5874..e47dfe5 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -465,10 +465,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
 	if (likely(fdb)) {
 		/* attempt to update an entry for a local interface */
 		if (unlikely(fdb->is_local)) {
-			if (net_ratelimit())
-				br_warn(br, "received packet on %s with "
-					"own address as source address\n",
-					source->dev->name);
+			net_ratelimited_function(br_warn, br, "received packet on %s "
+				"with own address as source address\n", source->dev->name);
 		} else {
 			/* fastpath: update of existing entry */
 			fdb->dst = source;
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index d1c5786..c00d8a2 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -530,11 +530,8 @@ static struct net_bridge_mdb_entry *br_multicast_get_group(
 	max = mdb->max;
 
 	if (unlikely(count > br->hash_elasticity && count)) {
-		if (net_ratelimit())
-			br_info(br, "Multicast hash table "
-				"chain limit reached: %s\n",
-				port ? port->dev->name : br->dev->name);
-
+		net_ratelimited_function(br_info, br, "Multicast hash table "
+			"chain limit reached: %s\n", port ? port->dev->name : br->dev->name);
 		elasticity = br->hash_elasticity;
 	}
 
@@ -554,10 +551,8 @@ disable:
 
 	if (max > mdb->max || elasticity) {
 		if (mdb->old) {
-			if (net_ratelimit())
-				br_info(br, "Multicast hash table "
-					"on fire: %s\n",
-					port ? port->dev->name : br->dev->name);
+			net_ratelimited_function(br_info, br, "Multicast hash table "
+				"on fire: %s\n", port ? port->dev->name : br->dev->name);
 			err = -EEXIST;
 			goto err;
 		}
diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c
index 8660ea3..482ef11 100644
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -220,13 +220,10 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
 		bpdu.forward_delay = br_get_ticks(buf+30);
 
 		if (bpdu.message_age > bpdu.max_age) {
-			if (net_ratelimit())
-				br_notice(p->br,
-					  "port %u config from %pM"
-					  " (message_age %ul > max_age %ul)\n",
-					  p->port_no,
-					  eth_hdr(skb)->h_source,
-					  bpdu.message_age, bpdu.max_age);
+			net_ratelimited_function(br_notice, p->br,
+				"port %u config from %pM (message_age %ul > max_age %ul)\n",
+				p->port_no, eth_hdr(skb)->h_source,
+				bpdu.message_age, bpdu.max_age);
 			goto out;
 		}
 
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 54395d7..35b8b1d 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -3156,10 +3156,8 @@ static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
 	if (!consume) {
 		skb = skb_copy(skb, GFP_ATOMIC);
 		if (!skb) {
-			if (net_ratelimit())
-				wiphy_debug(local->hw.wiphy,
-					"failed to copy skb for %s\n",
-					sdata->name);
+			net_ratelimited_function(wiphy_debug, local->hw.wiphy,
+				"failed to copy skb for %s\n", sdata->name);
 			return true;
 		}
 
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
index 707bc52..6179436 100644
--- a/net/netfilter/ipset/ip_set_hash_gen.h
+++ b/net/netfilter/ipset/ip_set_hash_gen.h
@@ -607,8 +607,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,
 		mtype_expire(h, NETS_LENGTH(set->family), h->dsize);
 
 	if (h->elements >= h->maxelem) {
-		if (net_ratelimit())
-			pr_warning("Set %s is full, maxelem %u reached\n",
+		net_warn_ratelimited("Set %s is full, maxelem %u reached\n",
 				   set->name, h->maxelem);
 		return -IPSET_ERR_HASH_FULL;
 	}
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH 01/18] netfilter: cleanup: delete Macro PRINTR
From: Kefeng Wang @ 2013-10-15 11:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev
In-Reply-To: <1381837514-50660-1-git-send-email-wangkefeng.wang@huawei.com>

Macro PRINTR is only used once in nfnetlink_log.c, so it can be
replaced by helper function net_err_ratelimited().

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 net/netfilter/nfnetlink_log.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index d92cc31..8713111 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -47,9 +47,6 @@
 #define NFULNL_QTHRESH_DEFAULT 	100	/* 100 packets */
 #define NFULNL_COPY_RANGE_MAX	0xFFFF	/* max packet size is limited by 16-bit struct nfattr nfa_len field */
 
-#define PRINTR(x, args...)	do { if (net_ratelimit()) \
-				     printk(x, ## args); } while (0);
-
 struct nfulnl_instance {
 	struct hlist_node hlist;	/* global list of instances */
 	spinlock_t lock;
@@ -587,7 +584,7 @@ __build_packet_message(struct nfnl_log_net *log,
 	return 0;
 
 nla_put_failure:
-	PRINTR(KERN_ERR "nfnetlink_log: error creating log nlmsg\n");
+	net_err_ratelimited("nfnetlink_log: error creating log nlmsg\n");
 	return -1;
 }
 
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH 00/18] cleanup: wrapper functions of net_ratelimit() called to simplify code
From: Kefeng Wang @ 2013-10-15 11:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, David S. Miller, Pablo Neira Ayuso,
	Stephen Hemminger, Johannes Berg, John W. Linville,
	Stanislaw Gruszka, Johannes Berg, Francois Romieu, Ben Hutchings,
	Chas Williams, Marc Kleine-Budde, Samuel Ortiz, Paul Mackerras,
	Oliver Neukum, Konrad Rzeszutek Wilk, Boris Ostrovsky,
	David Vrabel, Rusty Russell, Michael S. Tsirkin, netfilter,
	netdev

Macro PRINTR is called only once in nfnetlink_log.c, and it can be 
replaced by wrappe function of net_ratelimit(), so kill it.

Meanwhile, I found many files could use wrappe functions of net_ratelimit()
to simplify, so I did.


Kefeng Wang (18):
  netfilter: cleanup: delete Macro PRINTR
  net: use wrapper functions of net_ratelimit() to simplify code
  rt18187se: use wrapper functions of net_ratelimit() to simplify code
  rt18192e: use wrapper functions of net_ratelimit() to simplify code
  rt18192u: use wrapper functions of net_ratelimit() to simplify code
  net: wireless: use wrapper functions of net_ratelimit() to simplify
    code
  net: ethernet: use wrapper functions of net_ratelimit() to simplify
    code
  atm: use wrapper functions of net_ratelimit() to simplify code
  block: aoe: use wrapper functions of net_ratelimit() to simplify code
  net: peak_usb: use wrapper functions of net_ratelimit() to simplify
    code
  net: hamradio: use wrapper functions of net_ratelimit() to simplify
    code
  net: irda: use wrapper functions of net_ratelimit() to simplify code
  net: ppp: use wrapper functions of net_ratelimit() to simplify code
  net: usb: use wrapper functions of net_ratelimit() to simplify code
  net: xen: use wrapper functions of net_ratelimit() to simplify code
  net: virtio: use wrapper functions of net_ratelimit() to simplify code
  net: vxlan: use wrapper functions of net_ratelimit() to simplify code
  net: wimax: use wrapper functions of net_ratelimit() to simplify code

 drivers/atm/solos-pci.c                            | 20 ++++-----
 drivers/block/aoe/aoenet.c                         |  4 +-
 drivers/net/can/usb/peak_usb/pcan_usb_core.c       | 11 ++---
 drivers/net/ethernet/aeroflex/greth.c              | 16 +++----
 drivers/net/ethernet/alteon/acenic.c               |  3 +-
 drivers/net/ethernet/arc/emac_main.c               |  7 ++--
 drivers/net/ethernet/broadcom/b44.c                |  4 +-
 drivers/net/ethernet/ethoc.c                       |  4 +-
 drivers/net/ethernet/faraday/ftgmac100.c           | 49 +++++++---------------
 drivers/net/ethernet/faraday/ftmac100.c            | 45 ++++++--------------
 drivers/net/ethernet/freescale/fec_mpc52xx.c       |  3 +-
 drivers/net/ethernet/ibm/emac/mal.c                | 15 ++-----
 drivers/net/ethernet/marvell/mv643xx_eth.c         |  6 +--
 drivers/net/ethernet/marvell/pxa168_eth.c          |  8 +---
 drivers/net/ethernet/marvell/sky2.c                | 42 +++++++------------
 drivers/net/ethernet/myricom/myri10ge/myri10ge.c   |  5 +--
 drivers/net/ethernet/realtek/r8169.c               | 13 +++---
 drivers/net/ethernet/sfc/rx.c                      |  8 ++--
 drivers/net/ethernet/sfc/siena_sriov.c             | 27 ++++--------
 drivers/net/ethernet/ti/davinci_emac.c             |  4 +-
 drivers/net/ethernet/tundra/tsi108_eth.c           | 12 ++----
 drivers/net/hamradio/6pack.c                       |  3 +-
 drivers/net/hamradio/bpqether.c                    |  3 +-
 drivers/net/irda/stir4200.c                        |  3 +-
 drivers/net/ppp/ppp_generic.c                      | 11 +++--
 drivers/net/usb/usbnet.c                           |  4 +-
 drivers/net/virtio_net.c                           |  3 +-
 drivers/net/vxlan.c                                |  3 +-
 drivers/net/wimax/i2400m/netdev.c                  |  3 +-
 drivers/net/wireless/adm8211.c                     |  5 +--
 drivers/net/wireless/ath/carl9170/cmd.c            | 15 +++----
 drivers/net/wireless/ath/carl9170/phy.c            |  7 +---
 drivers/net/wireless/ath/carl9170/rx.c             | 45 ++++++--------------
 drivers/net/wireless/ath/carl9170/usb.c            | 12 ++----
 drivers/net/wireless/hostap/hostap_80211_rx.c      |  8 +---
 drivers/net/wireless/hostap/hostap_80211_tx.c      | 13 ++----
 drivers/net/wireless/hostap/hostap_ap.c            |  6 +--
 drivers/net/wireless/hostap/hostap_hw.c            | 17 +++-----
 drivers/net/wireless/iwlegacy/3945-mac.c           |  4 +-
 drivers/net/wireless/iwlegacy/4965-mac.c           |  6 +--
 drivers/net/wireless/iwlwifi/pcie/rx.c             |  7 ++--
 drivers/net/wireless/libertas_tf/cmd.c             |  6 +--
 drivers/net/wireless/mwl8k.c                       |  5 +--
 drivers/net/wireless/orinoco/hermes.c              |  6 +--
 drivers/net/wireless/orinoco/main.c                | 16 +++----
 drivers/net/wireless/orinoco/orinoco_usb.c         |  3 +-
 drivers/net/wireless/p54/p54pci.c                  |  6 +--
 drivers/net/xen-netback/netback.c                  | 21 ++++------
 drivers/net/xen-netfront.c                         | 27 ++++--------
 .../rtl8187se/ieee80211/ieee80211_crypt_ccmp.c     | 16 ++-----
 .../rtl8187se/ieee80211/ieee80211_crypt_tkip.c     | 27 ++++--------
 drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c |  4 +-
 drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c |  7 +---
 drivers/staging/rtl8192e/rtllib_crypt_ccmp.c       | 13 ++----
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c       | 21 +++-------
 drivers/staging/rtl8192e/rtllib_rx.c               |  6 +--
 .../rtl8192u/ieee80211/ieee80211_crypt_ccmp.c      | 17 ++------
 .../rtl8192u/ieee80211/ieee80211_crypt_tkip.c      | 22 +++-------
 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c  |  7 +---
 drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c  |  4 +-
 net/bridge/br_fdb.c                                |  6 +--
 net/bridge/br_multicast.c                          | 13 ++----
 net/bridge/br_stp_bpdu.c                           | 11 ++---
 net/mac80211/rx.c                                  |  6 +--
 net/netfilter/ipset/ip_set_hash_gen.h              |  3 +-
 net/netfilter/nfnetlink_log.c                      |  5 +--
 66 files changed, 246 insertions(+), 516 deletions(-)

-- 
1.8.2.1

^ permalink raw reply

* Re: DomU's network interface will hung when Dom0 running 32bit
From: jianhai luan @ 2013-10-15 11:26 UTC (permalink / raw)
  To: Wei Liu; +Cc: Ian Campbell, xen-devel, netdev, ANNIE LI
In-Reply-To: <20131015100624.GB29436@zion.uk.xensource.com>


On 2013-10-15 18:06, Wei Liu wrote:
> On Tue, Oct 15, 2013 at 05:34:57PM +0800, jianhai luan wrote:
>> On 2013-10-15 16:43, Ian Campbell wrote:
>>> On Tue, 2013-10-15 at 10:44 +0800, jianhai luan wrote:
>>>> On 2013-10-14 19:19, Wei Liu wrote:
>>>>> On Sat, Oct 12, 2013 at 04:53:18PM +0800, jianhai luan wrote:
>>>>>> Hi Ian,
>>>>>>     I meet the DomU's network interface hung issue recently, and have
>>>>>> been working on the issue from that time. I find that DomU's network
>>>>>> interface, which send lesser package, will hung if Dom0 running
>>>>>> 32bit and DomU's up-time is very long.  I think that one jiffies
>>>>>> overflow bug exist in the function tx_credit_exceeded().
>>>>>>     I know the inline function time_after_eq(a,b) will process jiffies
>>>>>> overflow, but the function have one limit a should little that (b +
>>>>>> MAX_SIGNAL_LONG). If a large than the value, time_after_eq will
>>>>>> return false. The MAX_SINGNAL_LONG should be 0x7fffffff at 32-bit
>>>>>> machine.
>>>>>>     If DomU's network interface send lesser package (<0.5k/s if
>>>>>> jiffies=250 and credit_bytes=ULONG_MAX), jiffies will beyond out
>>>>>> (credit_timeout.expires + MAX_SIGNAL_LONG) and time_after_eq(now,
>>>>>> next_credit) will failure (should be true). So one timer which will
>>>>>> not be trigger in short time, and later process will be aborted when
>>>>>> timer_pending(&vif->credit_timeout) is true. The result will be
>>>>>> DomU's network interface will be hung in long time (> 40days).
>>>>>>     Please think about the below scenario:
>>>>>>     Condition:
>>>>>>       Dom0 running 32-bit and HZ = 1000
>>>>>>       vif->credit_timeout->expire = 0xffffffff, vif->remaining_credit
>>>>>> = 0xffffffff, vif->credit_usec=0 jiffies=0
>>>>>>       vif receive lesser package (DomU send lesser package). If the
>>>>>> value is litter than 2K/s, consume 4G(0xffffffff) will need 582.55
>>>>>> hours. jiffies will large than 0x7ffffff. we guess jiffies =
>>>>>> 0x800000ff, time_after_eq(0x800000ff, 0xffffffff) will failure, and
>>>>>> one time which expire is 0xfffffff will be pended into system. So
>>>>>> the interface will hung until jiffies recount 0xffffffff (that will
>>>>>> need very long time).
>>>>> If I'm not mistaken you meant time_after_eq(now, next_credit) in
>>>>> netback. How does next_credit become 0xffffffff?
>>>> I only assume the value is 0xfffffff, and the value of next_credit
>>>> isn't  point. If the delta between now and next_credit larger than
>>>> ULONG_MAX, time_after_eq will do wrong judge.
>>> So it sounds like we need a timer which is independent of the traffic
>>> being sent to keep credit_timeout.expires rolling over.
>>>
>>> Can you propose a patch?
>> Because credit_timeout.expire always after jiffies, i judge the
>> value over the range of time_after_eq() by time_before(now,
>> vif->credit_timeout.expires). please check the patch.
> I don't think this really fix the issue for you. You still have chance
> that now wraps around and falls between expires and next_credit. In that
> case it's stalled again.

if time_before(now, vif->credit_timeout.expires) is true, time wrap and 
do operation. Otherwise time_before(now, vif->credit_timeout.expires) 
isn't true, now - vif->credit_timeout.expires should be letter than 
ULONG_MAX/2. Because next_credit large than vif->credit_timeout.expires 
(next_crdit = vif->credit_timeout.expires + 
msecs_to_jiffies(vif->credit_usec/1000)), the delta between now and 
next_credit should be in range of time_after_eq().  So time_after_eq() 
do correctly judge.

Jason
>
> Wei.

^ permalink raw reply

* RE: [Ilw] drivers/net/wireless/iwlwifi/dvm/tx.c:456 iwlagn_tx_skb+0x6c5/0x883()
From: Grumbach, Emmanuel @ 2013-10-15 10:52 UTC (permalink / raw)
  To: Sander Eikelenboom, John W. Linville, Berg, Johannes,
	ilw-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
  Cc: ilw-VuQAYsv1563Yd54FQh9/CA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <9010061839.20131015123940-6SM94LqRVpn6gRhOQ7JHfg@public.gmane.org>

> 
> Hi,
> 
> I'm having a:
> 
> 02:00.0 Network controller: Intel Corporation Centrino Advanced-N 6235 (rev
> 24)
> 
> And i'm running into this warning on boot with a 3.11.2 and 3.12-rc5 kernel.
> 
> [   23.904950] ------------[ cut here ]------------
> [   23.904957] WARNING: CPU: 0 PID: 2531 at
> drivers/net/wireless/iwlwifi/dvm/tx.c:456 iwlagn_tx_skb+0x6c5/0x883()

Can you reproduce easily?
If yes, please reproduce with debug parameters:
modprobe iwlwifi debug=0xC0800000

Also, please enable MAC80211_HT_DEBUG

Thanks

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* drivers/net/wireless/iwlwifi/dvm/tx.c:456 iwlagn_tx_skb+0x6c5/0x883()
From: Sander Eikelenboom @ 2013-10-15 10:39 UTC (permalink / raw)
  To: John W. Linville, johannes.berg, ilw; +Cc: ilw, linux-wireless, netdev

Hi,

I'm having a:

02:00.0 Network controller: Intel Corporation Centrino Advanced-N 6235 (rev 24)

And i'm running into this warning on boot with a 3.11.2 and 3.12-rc5 kernel.

[   23.904950] ------------[ cut here ]------------
[   23.904957] WARNING: CPU: 0 PID: 2531 at drivers/net/wireless/iwlwifi/dvm/tx.c:456 iwlagn_tx_skb+0x6c5/0x883()
[   23.904959] Modules linked in:
[   23.904962] CPU: 0 PID: 2531 Comm: hostapd Not tainted 3.12.0-rc5+ #1
[   23.904963] Hardware name:                  /D53427RKE, BIOS RKPPT10H.86A.0017.2013.0425.1251 04/25/2013
[   23.904966]  0000000000000000 0000000000000009 ffffffff8189aa62 0000000000000000
[   23.904968]  ffffffff8105a4f2 ffff880058339a48 ffffffff815f8a04 0000000000000000
[   23.904970]  ffff8800560097b0 0000000000000208 0000000000000000 ffff8800561a9e5e
[   23.904971] Call Trace:
[   23.904977]  [<ffffffff8189aa62>] ? dump_stack+0x41/0x51
[   23.904981]  [<ffffffff8105a4f2>] ? warn_slowpath_common+0x78/0x90
[   23.904984]  [<ffffffff815f8a04>] ? iwlagn_tx_skb+0x6c5/0x883
[   23.904986]  [<ffffffff815f8a04>] ? iwlagn_tx_skb+0x6c5/0x883
[   23.904989]  [<ffffffff818a0040>] ? put_cred+0x15/0x15
[   23.904991]  [<ffffffff815f6db4>] ? iwlagn_mac_tx+0x19/0x2f
[   23.904995]  [<ffffffff8186cc45>] ? __ieee80211_tx+0x226/0x29b
[   23.904998]  [<ffffffff8186e6bd>] ? ieee80211_tx+0xa6/0xb5
[   23.905001]  [<ffffffff8186e98b>] ? ieee80211_monitor_start_xmit+0x1e9/0x204
[   23.905005]  [<ffffffff8171ce5f>] ? dev_hard_start_xmit+0x271/0x3ec
[   23.905008]  [<ffffffff817351ac>] ? sch_direct_xmit+0x66/0x164
[   23.905010]  [<ffffffff8171d1bf>] ? dev_queue_xmit+0x1e5/0x3c8
[   23.905013]  [<ffffffff817fac5a>] ? packet_sendmsg+0xac5/0xb3d
[   23.905017]  [<ffffffff81709a09>] ? sock_sendmsg+0x37/0x52
[   23.905020]  [<ffffffff810f9e0c>] ? __do_fault+0x338/0x36b
[   23.905023]  [<ffffffff81713820>] ? verify_iovec+0x44/0x94
[   23.905025]  [<ffffffff81709e63>] ? ___sys_sendmsg+0x1f1/0x283
[   23.905029]  [<ffffffff81140a73>] ? __inode_wait_for_writeback+0x67/0xae
[   23.905031]  [<ffffffff8111735e>] ? __cache_free.isra.46+0x178/0x187
[   23.905033]  [<ffffffff811173b1>] ? kmem_cache_free+0x44/0x84
[   23.905036]  [<ffffffff81132c22>] ? dentry_kill+0x13d/0x149
[   23.905038]  [<ffffffff81132f6f>] ? dput+0xe5/0xef
[   23.905041]  [<ffffffff81136e04>] ? fget_light+0x2e/0x7c
[   23.905043]  [<ffffffff8170ae62>] ? __sys_sendmsg+0x39/0x57
[   23.905046]  [<ffffffff818a7e39>] ? system_call_fastpath+0x16/0x1b
[   23.905047] ---[ end trace 1b3eb79359c1d1e6 ]---

--
Sander

^ permalink raw reply

* Re: DomU's network interface will hung when Dom0 running 32bit
From: Wei Liu @ 2013-10-15 10:06 UTC (permalink / raw)
  To: jianhai luan; +Cc: Ian Campbell, Wei Liu, xen-devel, netdev, ANNIE LI
In-Reply-To: <525D0C41.2080407@oracle.com>

On Tue, Oct 15, 2013 at 05:34:57PM +0800, jianhai luan wrote:
> 
> On 2013-10-15 16:43, Ian Campbell wrote:
> >On Tue, 2013-10-15 at 10:44 +0800, jianhai luan wrote:
> >>On 2013-10-14 19:19, Wei Liu wrote:
> >>>On Sat, Oct 12, 2013 at 04:53:18PM +0800, jianhai luan wrote:
> >>>>Hi Ian,
> >>>>    I meet the DomU's network interface hung issue recently, and have
> >>>>been working on the issue from that time. I find that DomU's network
> >>>>interface, which send lesser package, will hung if Dom0 running
> >>>>32bit and DomU's up-time is very long.  I think that one jiffies
> >>>>overflow bug exist in the function tx_credit_exceeded().
> >>>>    I know the inline function time_after_eq(a,b) will process jiffies
> >>>>overflow, but the function have one limit a should little that (b +
> >>>>MAX_SIGNAL_LONG). If a large than the value, time_after_eq will
> >>>>return false. The MAX_SINGNAL_LONG should be 0x7fffffff at 32-bit
> >>>>machine.
> >>>>    If DomU's network interface send lesser package (<0.5k/s if
> >>>>jiffies=250 and credit_bytes=ULONG_MAX), jiffies will beyond out
> >>>>(credit_timeout.expires + MAX_SIGNAL_LONG) and time_after_eq(now,
> >>>>next_credit) will failure (should be true). So one timer which will
> >>>>not be trigger in short time, and later process will be aborted when
> >>>>timer_pending(&vif->credit_timeout) is true. The result will be
> >>>>DomU's network interface will be hung in long time (> 40days).
> >>>>    Please think about the below scenario:
> >>>>    Condition:
> >>>>      Dom0 running 32-bit and HZ = 1000
> >>>>      vif->credit_timeout->expire = 0xffffffff, vif->remaining_credit
> >>>>= 0xffffffff, vif->credit_usec=0 jiffies=0
> >>>>      vif receive lesser package (DomU send lesser package). If the
> >>>>value is litter than 2K/s, consume 4G(0xffffffff) will need 582.55
> >>>>hours. jiffies will large than 0x7ffffff. we guess jiffies =
> >>>>0x800000ff, time_after_eq(0x800000ff, 0xffffffff) will failure, and
> >>>>one time which expire is 0xfffffff will be pended into system. So
> >>>>the interface will hung until jiffies recount 0xffffffff (that will
> >>>>need very long time).
> >>>If I'm not mistaken you meant time_after_eq(now, next_credit) in
> >>>netback. How does next_credit become 0xffffffff?
> >>I only assume the value is 0xfffffff, and the value of next_credit
> >>isn't  point. If the delta between now and next_credit larger than
> >>ULONG_MAX, time_after_eq will do wrong judge.
> >So it sounds like we need a timer which is independent of the traffic
> >being sent to keep credit_timeout.expires rolling over.
> >
> >Can you propose a patch?
> 
> Because credit_timeout.expire always after jiffies, i judge the
> value over the range of time_after_eq() by time_before(now,
> vif->credit_timeout.expires). please check the patch.

I don't think this really fix the issue for you. You still have chance
that now wraps around and falls between expires and next_credit. In that
case it's stalled again.

Wei.

^ permalink raw reply

* transmit lockup using smsc95xx ethernet on usb3
From: David Laight @ 2013-10-15  9:59 UTC (permalink / raw)
  To: netdev, linux-usb

We are seeing complete lockups of the transmit side when using
the smsc95xx driver connected to a USB3 port on an i7 (Ivybridge) cpu.
These errors are very intermittent - less than once a day, and
it isn't actually clear that they are related to traffic load.

Most of the systems are running the 3.2 kernel from Ubuntu 12.04
but I've seen the same problem when running a 3.4 kernel.
Looking at the changelog for xhci-ring.c I can see that some
'nasty' bugs were fixed between 3.2 and 3.4 (and possibly since)
but the usbmon trace I've now got doesn't seem to match any
of the changelog entries.

We are also seeing similar problems if we connect to a USB2
header.

Since we can't reproduce the problem quickly it is difficult to
do any analysis. Any suggestions for increasing the error rate
would be welcome.

Below is an annotated extract from a usbmon trace while running
a netperf test that was sending 8192 byte TCP packets (nagle off).
I've deleted the Bi entries (packets are received throughout)
and numbered all the others (modulo 10000) so it is easier to
see when the requests complete, I've also calculated the elapsed
time and the number of Setup entries between the S and C traces.

The USB ring seems to have 60 outstanding transmits in it,
each time one completes another is sent. There are a few 10000
traces of that then:

  start:9870         ffff88020ea16000 293811125 S Bo:3:003:2 -115 1514 =
                        e2350000 e2450000 22003200 00224d98
                        d8460002 1f0057d7 08004500 05d0ff11
   done:9811:6969:60 ffff88020c7c8000 293811236 C Bo:3:003:2 0 1090 >
  start:9871         ffff88020ea16a80 293811242 S Bo:3:003:2 -115 1090 =
                        3a340000 3a440000 22003200 00224d98
                        d8460002 1f0057d7 08004500 0428ff12
...
  start:9929         ffff88020ea16780 293817964 S Bo:3:003:2 -115 1514 =
                        e2350000 e2450000 22003200 00224d98
                        d8460002 1f0057d7 08004500 05d0ff4c
Last successful completion.
   done:9870:6968:60 ffff88020ea16000 293818093 C Bo:3:003:2 0 1514 >
  start:9930         ffff88020ea16000 293818099 S Bo:3:003:2 -115 1514 =
                        e2350000 e2450000 22003200 00224d98
                        d8460002 1f0057d7 08004500 05d0ff4d

At this point something (untraced) seems to have gone horribly
wrong in the transmit ring. dmesg shows nothing.
Two Bo 'fail -71', 6 succeed, one fails -32 the rest fail -104.
   done:9871:6913:60 ffff88020ea16a80 293818155 C Bo:3:003:2 -71 512 >
   done:9872:6927:59 ffff88020ea16f00 293818235 C Bo:3:003:2 -71 0
   done:9873:6875:58 ffff88020ea16480 293818313 C Bo:3:003:2 0 1514 >
   done:9874:6786:57 ffff88020c7c83c0 293818353 C Bo:3:003:2 0 1514 >
   done:9875:6794:56 ffff88020c7c80c0 293818470 C Bo:3:003:2 0 1514 >
   done:9876:6789:55 ffff88020c7c8e40 293818589 C Bo:3:003:2 0 1514 >
   done:9877:6775:54 ffff88020c7c8240 293818702 C Bo:3:003:2 0 1090 >
   done:9878:6751:53 ffff88020c7c8180 293818803 C Bo:3:003:2 0 1514 >
   done:9879:6735:52 ffff88020c7c89c0 293818885 C Bo:3:003:2 -32 0
   done:9880:6671:51 ffff88020c7c8900 293818925 C Bo:3:003:2 -104 0
...
    done:9927:1292:4 ffff88020cf0c480 293819015 C Bo:3:003:2 -104 0
    done:9928:1170:3 ffff88020ea160c0 293819016 C Bo:3:003:2 -104 0
Something is known to be wrong...
  start:9931         ffff88020ea160c0 293819037 S Co:3:003:0
                         s 02 01 0000 0002 0000 0
    done:9929:1080:3 ffff88020ea16780 293819044 C Bo:3:003:2 -104 0
     done:9930:945:2 ffff88020ea16000 293819044 C Bo:3:003:2 -104 0
      done:9931:48:1 ffff88020ea160c0 293819085 C Co:3:003:0 0 0

These 10 transmits never finish:
  start:9932         ffff88020ea160c0 293819098 S Bo:3:003:2 -115 1090 =
                        3a340000 3a440000 22003200 00224d98
                        d8460002 1f0057d7 08004500 0428ff4e
... 9933 to 9940 deleted
  start:9941         ffff88020ea16b40 293819111 S Bo:3:003:2 -115 1514 =
                        e2350000 e2450000 22003200 00224d98
                        d8460002 1f0057d7 08004500 05d0ff57

All further transmits fail immediately E -12 and generate the
    'xhci_hcd 0000:00:14.0: ERROR no room on ep ring' message.
(There are 1070 'E' traces and 1070 'no room' messages.)
Receives are still working.
  start:9942         ffff88020ea16240 293819113 S Bo:3:003:2 -115 1514 =
                        e2350000 e2450000 22003200 00224d98
                        d8460002 1f0057d7 08004500 05d0ff58
    done:9942:1550:1 ffff88020ea16240 293820663 E Bo:3:003:2 -12 0
  start:9943         ffff88020ea16240 293820675 S Bo:3:003:2 -115 1514 =
                        e2350000 e2450000 22003200 00224d98
                        d8460002 1f0057d7 08004500 05d0ff59
    done:9943:1507:1 ffff88020ea16240 293822182 E Bo:3:003:2 -12 0

Eventually something causes a device remove and insert - everything re-initialises.
This is over 12 hours later.
      done:unknown   ffff88020c8570c0 3637139297 C Ii:3:001:1 0:2048 1 = 02
  start:1015         ffff88020c8570c0 3637139302 S Ii:3:001:1 -115:2048 4 <
  start:1016         ffff88020cbeb300 3637139323 S Ci:3:001:0
                         s a3 00 0000 0001 0004 4 <
                     ffff88020ea16240 3637139331 C Bi:3:003:1 -71 0
       done:1016:9:1 ffff88020cbeb300 3637139332 C Ci:3:001:0 0 4 = 00010100
  start:1017         ffff88020cbeb300 3637139334 S Co:3:001:0
                         s 23 01 0010 0001 0000 0
       done:1017:4:1 ffff88020cbeb300 3637139338 C Co:3:001:0 0 0
      done:unknown   ffff88020ca9ae40 3637139423 C Ii:3:003:3 -71:1 0
                     ffff88020c9db540 3637139428 C Bi:3:003:1 -108 0
                     ffff88020c9db780 3637139430 C Bi:3:003:1 -108 0
                     ffff88020d8bb540 3637139431 C Bi:3:003:1 -108 0

The last 10 transmits then terminate with error -108:
 done:9932:xxxx      ffff88020ea160c0 3637139462 C Bo:3:003:2 -108 0
... 9933 to 9940 deleted
 done:9941:xxxx      ffff88020ea16b40 3637139482 C Bo:3:003:2 -108 0
   done:1015:21090:3 ffff88020c8570c0 3637160392 C Ii:3:001:1 0:2048 1 = 02
  start:1018         ffff88020c8570c0 3637160396 S Ii:3:001:1 -115:2048 4 <
      done:unknown   ffff88020cbf26c0 3637176790 C Ii:3:005:1 -108:8 0
      done:unknown   ffff88020c68aa80 3637622497 C Ii:3:002:1 -108:2048 0

Followed by lots of Ci/Co and eventually it all starts working again.

I've not yet tried to look up the control transfers.

These aren't the only errors we are seeing, we also see (separately):
[21549.917529] hub 3-2:1.0: port 1 disabled by hub (EMI?), re-enabling...
[ 5822.629579] NETDEV WATCHDOG: eth0 (smsc95xx): transmit queue 0 timed out
[ 7263.834404] hid-generic 0003:413C:2005.0002: can't reset device, 0000:00:1a.0-1.4.3/input0, status -71 (connected to a USB2 header).
These all cause a USB bus reset and everything recovers within a couple of seconds.

	David

^ permalink raw reply

* Re: [PATCH] staging: octeon-ethernet: trivial: Avoid OOPS if phydev is not set
From: Dan Carpenter @ 2013-10-15  9:47 UTC (permalink / raw)
  To: Aaro Koskinen
  Cc: support, David Daney, Greg KH, driverdev-devel,
	Sebastian Pöhn, netdev
In-Reply-To: <20131014194937.GD4260@blackmetal.musicnaut.iki.fi>

On Mon, Oct 14, 2013 at 10:49:37PM +0300, Aaro Koskinen wrote:
> On Mon, Oct 14, 2013 at 10:16:49PM +0300, Dan Carpenter wrote:
> > On Mon, Oct 14, 2013 at 09:39:06PM +0300, Aaro Koskinen wrote:
> > > It's initialized in cvm_oct_phy_setup_device():
> > > 
> > > 	priv->phydev = of_phy_connect(dev, phy_node, cvm_oct_adjust_link, 0,
> >       ^^^^^^^^^^^^                                 ^^^^^^^^^^^^^^^^^^^
> > 
> > Sorry I should have explained better.
> > 
> > We use cvm_oct_adjust_link() to initialize priv->phydev but
> > cvm_oct_adjust_link() depends on priv->phydev.  It seems like we would
> > hit the NULL dereference every time.  Weird huh?
> 
> It doesn't happen on my system (EdgeRouter Lite). I think you need to
> explain even more better. :-)
> 
> What you mean by "We use cvm_oct_adjust_link() to initialize
> priv->phydev..."? Sorry, maybe I'm just missing something really
> obvious...

Hm...  I didn't followed the state machine all the way through so I'm
not actually sure how this is called.  But it's weird that priv->phydev
is initialized on the left side of the assignment but dereferenced in
the function mentioned on the right side if the assignment.

Also this patch should not be marked as "trivial" in the subject.
"trivial" is only for spelling mistakes in comments etc.

regards,
dan carpenter

^ permalink raw reply

* Re: [PATCH ipsec] xfrm: prevent ipcomp scratch buffer race condition
From: Steffen Klassert @ 2013-10-15  9:46 UTC (permalink / raw)
  To: Fan Du; +Cc: Michal Kubecek, Herbert Xu, David S. Miller, netdev
In-Reply-To: <525D03D8.7060802@windriver.com>

On Tue, Oct 15, 2013 at 04:59:04PM +0800, Fan Du wrote:
> 
> 
> On 2013年10月15日 16:33, Steffen Klassert wrote:
> >
> >Maybe we could disable the BHs before we fetch the percpu pointers.
> >Then we can use smp_processor_id() to get the cpu. With that we
> >could get rid of a (now useless) preempt_disable()/preempt_enable()
> >pair. Same could be done in ipcomp_compress().
> 
> Is it possible that two tasks race scratch buffer when both of them trying to compress data
> without preempt disabled? for example, when task A working on compression, then task B
> with higher priority preempts task A, and try to touch scratch buffer, which leaves stale
> data for task A after then.
> 
> I think we needs preempt disabled for such case, otherwise I overlook codes in somewhere else.
> 

You overlook that preemption is disabled if the BHs are disabled.

^ permalink raw reply

* Re: DomU's network interface will hung when Dom0 running 32bit
From: jianhai luan @ 2013-10-15  9:34 UTC (permalink / raw)
  To: Ian Campbell; +Cc: Wei Liu, xen-devel, netdev, ANNIE LI
In-Reply-To: <1381826609.24708.135.camel@kazak.uk.xensource.com>

[-- Attachment #1: Type: text/plain, Size: 2838 bytes --]


On 2013-10-15 16:43, Ian Campbell wrote:
> On Tue, 2013-10-15 at 10:44 +0800, jianhai luan wrote:
>> On 2013-10-14 19:19, Wei Liu wrote:
>>> On Sat, Oct 12, 2013 at 04:53:18PM +0800, jianhai luan wrote:
>>>> Hi Ian,
>>>>     I meet the DomU's network interface hung issue recently, and have
>>>> been working on the issue from that time. I find that DomU's network
>>>> interface, which send lesser package, will hung if Dom0 running
>>>> 32bit and DomU's up-time is very long.  I think that one jiffies
>>>> overflow bug exist in the function tx_credit_exceeded().
>>>>     I know the inline function time_after_eq(a,b) will process jiffies
>>>> overflow, but the function have one limit a should little that (b +
>>>> MAX_SIGNAL_LONG). If a large than the value, time_after_eq will
>>>> return false. The MAX_SINGNAL_LONG should be 0x7fffffff at 32-bit
>>>> machine.
>>>>     If DomU's network interface send lesser package (<0.5k/s if
>>>> jiffies=250 and credit_bytes=ULONG_MAX), jiffies will beyond out
>>>> (credit_timeout.expires + MAX_SIGNAL_LONG) and time_after_eq(now,
>>>> next_credit) will failure (should be true). So one timer which will
>>>> not be trigger in short time, and later process will be aborted when
>>>> timer_pending(&vif->credit_timeout) is true. The result will be
>>>> DomU's network interface will be hung in long time (> 40days).
>>>>     Please think about the below scenario:
>>>>     Condition:
>>>>       Dom0 running 32-bit and HZ = 1000
>>>>       vif->credit_timeout->expire = 0xffffffff, vif->remaining_credit
>>>> = 0xffffffff, vif->credit_usec=0 jiffies=0
>>>>       vif receive lesser package (DomU send lesser package). If the
>>>> value is litter than 2K/s, consume 4G(0xffffffff) will need 582.55
>>>> hours. jiffies will large than 0x7ffffff. we guess jiffies =
>>>> 0x800000ff, time_after_eq(0x800000ff, 0xffffffff) will failure, and
>>>> one time which expire is 0xfffffff will be pended into system. So
>>>> the interface will hung until jiffies recount 0xffffffff (that will
>>>> need very long time).
>>> If I'm not mistaken you meant time_after_eq(now, next_credit) in
>>> netback. How does next_credit become 0xffffffff?
>> I only assume the value is 0xfffffff, and the value of next_credit
>> isn't  point. If the delta between now and next_credit larger than
>> ULONG_MAX, time_after_eq will do wrong judge.
> So it sounds like we need a timer which is independent of the traffic
> being sent to keep credit_timeout.expires rolling over.
>
> Can you propose a patch?

Because credit_timeout.expire always after jiffies, i judge the value 
over the range of time_after_eq() by time_before(now, 
vif->credit_timeout.expires). please check the patch.
>
> Ian.
>
>>> Wei.
>>>
>>>>     If some error exist in above explain, please help me point it out.
>>>>
>>>> Thanks,
>>>> Jason
>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Process-the-wrong-judge-of-time_after_eq.patch --]
[-- Type: text/plain; charset=gb18030; name="0001-Process-the-wrong-judge-of-time_after_eq.patch", Size: 1206 bytes --]

From f08c584ca1f393f6559b58b6b4c9e259c313259e Mon Sep 17 00:00:00 2001
From: Jason Luan <jianhai.luan@oracle.com>
Date: Tue, 15 Oct 2013 17:07:49 +0800
Subject: [PATCH] Process the wrong judge of time_after_eq().

If netfront send lesser package, the delta between now and next_credit will be out range of time_after_qe() and the function will do wrong judge. Because the expires always after jiffies, we judge the condition by time_before(now, vif->credit_timeout.expires).

Signed-off-by: Jason Luan <jianhai.luan@oracle.com>
---
 drivers/net/xen-netback/netback.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index f3e591c..8036ce6 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1195,7 +1195,8 @@ static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
 		return true;
 
 	/* Passed the point where we can replenish credit? */
-	if (time_after_eq(now, next_credit)) {
+	if (time_after_eq(now, next_credit) ||
+		unlikely(time_before(now, vif->credit_timeout.expires))) {
 		vif->credit_timeout.expires = now;
 		tx_add_credit(vif);
 	}
-- 
1.7.6.5


^ permalink raw reply related

* [PATCHv3 net] {xfrm, sctp} Stick to software crc32 even if hardware is capable of that
From: Fan Du @ 2013-10-15  9:19 UTC (permalink / raw)
  To: vyasevich, nhorman; +Cc: steffen.klassert, davem, netdev

igb/ixgbe have hardware sctp checksum support, when this feature is enabled
and also IPsec is armed to protect sctp traffic, ugly things happened as
xfrm_output checks CHECKSUM_PARTIAL to do check sum operation(sum every thing
up and pack the 16bits result in the checksum field). The result is fail
establishment of sctp communication.

Signed-off-by: Fan Du <fan.du@windriver.com>
Cc: Vlad Yasevich <vyasevich@gmail.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
---
v3:
  - Rename is_xfrm_armed by dst_xfrm
  - Move this funtion in include/net/dst.h

v2:
  - Split v1 into two separate patches.

---
 include/net/dst.h |   12 ++++++++++++
 net/sctp/output.c |    3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/net/dst.h b/include/net/dst.h
index 211dcf1..44995c1 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -478,10 +478,22 @@ static inline struct dst_entry *xfrm_lookup(struct net *net,
 {
 	return dst_orig;
 } 
+
+static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
+{
+	return NULL;
+}
+
 #else
 struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
 			      const struct flowi *fl, struct sock *sk,
 			      int flags);
+
+/* skb attached with this dst needs transformation if dst->xfrm is valid */
+static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
+{
+	return dst->xfrm;
+}
 #endif
 
 #endif /* _NET_DST_H */
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 0ac3a65..24b3718 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -536,7 +536,8 @@ int sctp_packet_transmit(struct sctp_packet *packet)
 	 * by CRC32-C as described in <draft-ietf-tsvwg-sctpcsum-02.txt>.
 	 */
 	if (!sctp_checksum_disable) {
-		if (!(dst->dev->features & NETIF_F_SCTP_CSUM)) {
+		if (!(dst->dev->features & NETIF_F_SCTP_CSUM) ||
+			(dst_xfrm(dst) != NULL)) {
 			__u32 crc32 = sctp_start_cksum((__u8 *)sh, cksum_buf_len);
 
 			/* 3) Put the resultant value into the checksum field in the
-- 
1.7.9.5

^ permalink raw reply related

* Re: [PATCHv2 RESEND] {xfrm, sctp} Stick to software crc32 even if hardware is capable of that
From: Fan Du @ 2013-10-15  9:17 UTC (permalink / raw)
  To: Vlad Yasevich; +Cc: Daniel Borkmann, nhorman, steffen.klassert, davem, netdev
In-Reply-To: <fed034cb-be28-488b-883f-627e8e7499b9@email.android.com>



On 2013年10月14日 22:16, Vlad Yasevich wrote:
>
>
> Fan Du<fan.du@windriver.com>  wrote:
>
>>
>>
>> On 2013年10月14日 16:07, Daniel Borkmann wrote:
>>> On 10/14/2013 09:27 AM, Fan Du wrote:
>>>> igb/ixgbe have hardware sctp checksum support, when this feature is
>> enabled
>>>> and also IPsec is armed to protect sctp traffic, ugly things
>> happened as
>>>> xfrm_output checks CHECKSUM_PARTIAL to do check sum operation(sum
>> every thing
>>>> up and pack the 16bits result in the checksum field). The result is
>> fail
>>>> establishment of sctp communication.
>>>>
>>>> Signed-off-by: Fan Du<fan.du@windriver.com>
>>>> Cc: Vlad Yasevich<vyasevich@gmail.com>
>>>> Cc: Neil Horman<nhorman@tuxdriver.com>
>>>> Cc: Steffen Klassert<steffen.klassert@secunet.com>
>>>> Acked-by: Vlad Yasevich<vyasevich@gmail.com>
>>>> ---
>>>>    net/sctp/output.c |   14 +++++++++++++-
>>>>    1 file changed, 13 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/net/sctp/output.c b/net/sctp/output.c
>>>> index 0ac3a65..6de6402 100644
>>>> --- a/net/sctp/output.c
>>>> +++ b/net/sctp/output.c
>>>> @@ -372,6 +372,16 @@ static void sctp_packet_set_owner_w(struct
>> sk_buff *skb, struct sock *sk)
>>>>        atomic_inc(&sk->sk_wmem_alloc);
>>>>    }
>>>>
>>>> +static int is_xfrm_armed(struct dst_entry *dst)
>>>> +{
>>>> +#ifdef CONFIG_XFRM
>>>> +    /* If dst->xfrm is valid, this skb needs to be transformed */
>>>> +    return dst->xfrm != NULL;
>>>> +#else
>>>> +    return 0;
>>>> +#endif
>>>> +}
>>>
>>> Instead of putting this into SCTP code, isn't the above rather a
>> candidate for
>>> include/net/xfrm.h, e.g. as ... bool xfrm_is_armed(...) ?
>>
>> Should be in such style in terms of its name, but this is truly SCTP
>> specific in this scenario.
>> No one elsewhere barely need this as far as I can tell...
>
> It almost begs for dst_xfrm() function that returns NULL or dst->xfrm.
> Thar can live in dst code.

Ok, I will show my love in such style in v3.

> -vlad
>

-- 
浮沉随浪只记今朝笑

--fan

^ permalink raw reply

* Re: [PATCH ipsec] xfrm: prevent ipcomp scratch buffer race condition
From: Fan Du @ 2013-10-15  8:59 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: Michal Kubecek, Herbert Xu, David S. Miller, netdev
In-Reply-To: <20131015083348.GW7660@secunet.com>



On 2013年10月15日 16:33, Steffen Klassert wrote:
> On Mon, Oct 14, 2013 at 06:03:34PM +0200, Michal Kubecek wrote:
>> In ipcomp_compress(), sortirq is enabled too early, allowing the
>> per-cpu scratch buffer to be rewritten by ipcomp_decompress()
>> (called on the same CPU in softirq context) between populating
>> the buffer and copying the compressed data to the skb.
>>
>> Add similar protection into ipcomp_decompress() as it can be
>> called from process context as well (even if such scenario seems
>> a bit artificial).
>>
>> Signed-off-by: Michal Kubecek<mkubecek@suse.cz>
>> ---
>>   net/xfrm/xfrm_ipcomp.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
>> index 2906d52..96946fb 100644
>> --- a/net/xfrm/xfrm_ipcomp.c
>> +++ b/net/xfrm/xfrm_ipcomp.c
>> @@ -48,9 +48,11 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
>>   	const int cpu = get_cpu();
>>   	u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
>>   	struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
>> -	int err = crypto_comp_decompress(tfm, start, plen, scratch,&dlen);
>> +	int err;
>>   	int len;
>>
>> +	local_bh_disable();
>
> Maybe we could disable the BHs before we fetch the percpu pointers.
> Then we can use smp_processor_id() to get the cpu. With that we
> could get rid of a (now useless) preempt_disable()/preempt_enable()
> pair. Same could be done in ipcomp_compress().

Is it possible that two tasks race scratch buffer when both of them trying to compress data
without preempt disabled? for example, when task A working on compression, then task B
with higher priority preempts task A, and try to touch scratch buffer, which leaves stale
data for task A after then.

I think we needs preempt disabled for such case, otherwise I overlook codes in somewhere else.

> Looks ok otherwise. Thanks!
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-- 
浮沉随浪只记今朝笑

--fan

^ permalink raw reply

* Re: kernel policy routing table src ip not respected since 2.6.37 and commit 9fc3bbb4a752
From: Julian Anastasov @ 2013-10-15  8:51 UTC (permalink / raw)
  To: Vincent Li; +Cc: netdev@vger.kernel.org, jsing
In-Reply-To: <CAK3+h2zGFnbC-hpPB8fPX7TC3rKCWbPYVY4WW4HDYbN+LXNXXw@mail.gmail.com>


	Hello,

On Mon, 14 Oct 2013, Vincent Li wrote:

> I had a simple bash script to test if the policy routing table src ip
> is respected or not, git bisect found the  commit 9fc3bbb4a752 to
> change the policy routing table source ip behavior.
> 
> commit 9fc3bbb4a752f108cf096d96640f3b548bbbce6c
> Author: Joel Sing <jsing@google.com>
> Date:   Mon Jan 3 20:24:20 2011 +0000
> 
>     ipv4/route.c: respect prefsrc for local routes
> 
>     The preferred source address is currently ignored for local routes,
>     which results in all local connections having a src address that is the
>     same as the local dst address. Fix this by respecting the preferred source
>     address when it is provided for local routes.
> 
> test script:
> 
> #!/bin/bash
> ip addr add 10.1.1.1/24 dev eth0
> ip addr add 10.1.1.2/24 dev eth0
> ip rule add priority 245 table 245
> ip route add 10.1.1.0/24 dev eth0  proto kernel  scope link  src
> 10.1.1.2 table 245 <===source ip 10.1.1.2 to be preferred
> 
> ip addr show dev eth0
> ip route list table main
> ip route list table 245
> 
> 
> tcpdump -nn -i eth0 host 10.1.1.9 and icmp &
> 
> ping 10.1.1.9
> 
> 
> 
> --before commit 9fc3bbb4a752
> 
> the source is from ip 10.1.1.2 as expected
> 
> --after commit 9fc3bbb4a752
> 
> the source is from ip 10.1.1.1 which not expected since I have high
> priority table 245 with source ip 10.1.1.2
> 
> is this regression of commit 9fc3bbb4a752 ?

	Hm, it works here on 3.11.3. ARP request uses
10.1.1.2 and ICMP packet has such source. May be something with
the ping tool you are using? Check 'strace ping -c 1 10.1.1.9', may
be it binds to first device IP?

Regards

--
Julian Anastasov <ja@ssi.bg>

^ permalink raw reply

* Re: DomU's network interface will hung when Dom0 running 32bit
From: Ian Campbell @ 2013-10-15  8:43 UTC (permalink / raw)
  To: jianhai luan; +Cc: Wei Liu, xen-devel, netdev
In-Reply-To: <525CAC21.5040202@oracle.com>

On Tue, 2013-10-15 at 10:44 +0800, jianhai luan wrote:
> On 2013-10-14 19:19, Wei Liu wrote:
> > On Sat, Oct 12, 2013 at 04:53:18PM +0800, jianhai luan wrote:
> >> Hi Ian,
> >>    I meet the DomU's network interface hung issue recently, and have
> >> been working on the issue from that time. I find that DomU's network
> >> interface, which send lesser package, will hung if Dom0 running
> >> 32bit and DomU's up-time is very long.  I think that one jiffies
> >> overflow bug exist in the function tx_credit_exceeded().
> >>    I know the inline function time_after_eq(a,b) will process jiffies
> >> overflow, but the function have one limit a should little that (b +
> >> MAX_SIGNAL_LONG). If a large than the value, time_after_eq will
> >> return false. The MAX_SINGNAL_LONG should be 0x7fffffff at 32-bit
> >> machine.
> >>    If DomU's network interface send lesser package (<0.5k/s if
> >> jiffies=250 and credit_bytes=ULONG_MAX), jiffies will beyond out
> >> (credit_timeout.expires + MAX_SIGNAL_LONG) and time_after_eq(now,
> >> next_credit) will failure (should be true). So one timer which will
> >> not be trigger in short time, and later process will be aborted when
> >> timer_pending(&vif->credit_timeout) is true. The result will be
> >> DomU's network interface will be hung in long time (> 40days).
> >>    Please think about the below scenario:
> >>    Condition:
> >>      Dom0 running 32-bit and HZ = 1000
> >>      vif->credit_timeout->expire = 0xffffffff, vif->remaining_credit
> >> = 0xffffffff, vif->credit_usec=0 jiffies=0
> >>      vif receive lesser package (DomU send lesser package). If the
> >> value is litter than 2K/s, consume 4G(0xffffffff) will need 582.55
> >> hours. jiffies will large than 0x7ffffff. we guess jiffies =
> >> 0x800000ff, time_after_eq(0x800000ff, 0xffffffff) will failure, and
> >> one time which expire is 0xfffffff will be pended into system. So
> >> the interface will hung until jiffies recount 0xffffffff (that will
> >> need very long time).
> > If I'm not mistaken you meant time_after_eq(now, next_credit) in
> > netback. How does next_credit become 0xffffffff?
> 
> I only assume the value is 0xfffffff, and the value of next_credit 
> isn't  point. If the delta between now and next_credit larger than 
> ULONG_MAX, time_after_eq will do wrong judge.

So it sounds like we need a timer which is independent of the traffic
being sent to keep credit_timeout.expires rolling over.

Can you propose a patch?

Ian.

> >
> > Wei.
> >
> >>    If some error exist in above explain, please help me point it out.
> >>
> >> Thanks,
> >> Jason
> 

^ permalink raw reply

* Re: [PATCH ipsec] xfrm: prevent ipcomp scratch buffer race condition
From: Steffen Klassert @ 2013-10-15  8:33 UTC (permalink / raw)
  To: Michal Kubecek; +Cc: Herbert Xu, David S. Miller, netdev
In-Reply-To: <20131014160334.BCCDDE8A31@unicorn.suse.cz>

On Mon, Oct 14, 2013 at 06:03:34PM +0200, Michal Kubecek wrote:
> In ipcomp_compress(), sortirq is enabled too early, allowing the
> per-cpu scratch buffer to be rewritten by ipcomp_decompress()
> (called on the same CPU in softirq context) between populating
> the buffer and copying the compressed data to the skb.
> 
> Add similar protection into ipcomp_decompress() as it can be
> called from process context as well (even if such scenario seems
> a bit artificial).
> 
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
> ---
>  net/xfrm/xfrm_ipcomp.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
> index 2906d52..96946fb 100644
> --- a/net/xfrm/xfrm_ipcomp.c
> +++ b/net/xfrm/xfrm_ipcomp.c
> @@ -48,9 +48,11 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
>  	const int cpu = get_cpu();
>  	u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
>  	struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
> -	int err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
> +	int err;
>  	int len;
>  
> +	local_bh_disable();

Maybe we could disable the BHs before we fetch the percpu pointers.
Then we can use smp_processor_id() to get the cpu. With that we
could get rid of a (now useless) preempt_disable()/preempt_enable()
pair. Same could be done in ipcomp_compress().

Looks ok otherwise. Thanks!

^ permalink raw reply

* [PATCH net-next v2 2/3] bonding: use RCU protection for alb xmit path
From: Ding Tianhong @ 2013-10-15  8:28 UTC (permalink / raw)
  To: Jay Vosburgh, Andy Gospodarek, David S. Miller,
	Nikolay Aleksandrov, Veaceslav Falico, Netdev

The commit 278b20837511776dc9d5f6ee1c7fabd5479838bb
(bonding: initial RCU conversion) has convert the roundrobin,
active-backup, broadcast and xor xmit path to rcu protection,
the performance will be better for these mode, so this time,
convert xmit path for alb mode.

Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Cc: Nikolay Aleksandrov <nikolay@redhat.com>
Cc: Veaceslav Falico <vfalico@redhat.com>
---
 drivers/net/bonding/bond_alb.c | 58 +++++++++++++++++++++++++++++++-----------
 drivers/net/bonding/bonding.h  | 14 ++++++++++
 2 files changed, 57 insertions(+), 15 deletions(-)

diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 576ccea..0287240 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -230,7 +230,7 @@ static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
 	max_gap = LLONG_MIN;
 
 	/* Find the slave with the largest gap */
-	bond_for_each_slave(bond, slave, iter) {
+	bond_for_each_slave_rcu(bond, slave, iter) {
 		if (SLAVE_IS_OK(slave)) {
 			long long gap = compute_gap(slave);
 
@@ -412,6 +412,39 @@ static struct slave *rlb_next_rx_slave(struct bonding *bond)
 	return rx_slave;
 }
 
+/* Caller must hold rcu_read_lock() for read */
+static struct slave *__rlb_next_rx_slave(struct bonding *bond)
+{
+	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
+	struct slave *before = NULL, *rx_slave = NULL, *slave;
+	struct list_head *iter;
+	bool found = false;
+
+	bond_for_each_slave_rcu(bond, slave, iter) {
+		if (!SLAVE_IS_OK(slave))
+			continue;
+		if (!found) {
+			if (!before || before->speed < slave->speed)
+				before = slave;
+		} else {
+			if (!rx_slave || rx_slave->speed < slave->speed)
+				rx_slave = slave;
+		}
+		if (slave == bond_info->rx_slave)
+			found = true;
+	}
+	/* we didn't find anything after the current or we have something
+	 * better before and up to the current slave
+	 */
+	if (!rx_slave || (before && rx_slave->speed < before->speed))
+		rx_slave = before;
+
+	if (rx_slave)
+		bond_info->rx_slave = rx_slave;
+
+	return rx_slave;
+}
+
 /* teach the switch the mac of a disabled slave
  * on the primary for fault tolerance
  *
@@ -628,12 +661,14 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
 {
 	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
 	struct arp_pkt *arp = arp_pkt(skb);
-	struct slave *assigned_slave;
+	struct slave *assigned_slave, *curr_active_slave;
 	struct rlb_client_info *client_info;
 	u32 hash_index = 0;
 
 	_lock_rx_hashtbl(bond);
 
+	curr_active_slave = rcu_dereference(bond->curr_active_slave);
+
 	hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_dst));
 	client_info = &(bond_info->rx_hashtbl[hash_index]);
 
@@ -658,14 +693,14 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
 			 * that the new client can be assigned to this entry.
 			 */
 			if (bond->curr_active_slave &&
-			    client_info->slave != bond->curr_active_slave) {
-				client_info->slave = bond->curr_active_slave;
+			    client_info->slave != curr_active_slave) {
+				client_info->slave = curr_active_slave;
 				rlb_update_client(client_info);
 			}
 		}
 	}
 	/* assign a new slave */
-	assigned_slave = rlb_next_rx_slave(bond);
+	assigned_slave = __rlb_next_rx_slave(bond);
 
 	if (assigned_slave) {
 		if (!(client_info->assigned &&
@@ -728,7 +763,7 @@ static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
 	/* Don't modify or load balance ARPs that do not originate locally
 	 * (e.g.,arrive via a bridge).
 	 */
-	if (!bond_slave_has_mac(bond, arp->mac_src))
+	if (!bond_slave_has_mac_rcu(bond, arp->mac_src))
 		return NULL;
 
 	if (arp->op_code == htons(ARPOP_REPLY)) {
@@ -1343,11 +1378,6 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
 	skb_reset_mac_header(skb);
 	eth_data = eth_hdr(skb);
 
-	/* make sure that the curr_active_slave do not change during tx
-	 */
-	read_lock(&bond->lock);
-	read_lock(&bond->curr_slave_lock);
-
 	switch (ntohs(skb->protocol)) {
 	case ETH_P_IP: {
 		const struct iphdr *iph = ip_hdr(skb);
@@ -1429,12 +1459,12 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
 
 	if (!tx_slave) {
 		/* unbalanced or unassigned, send through primary */
-		tx_slave = bond->curr_active_slave;
+		tx_slave = rcu_dereference(bond->curr_active_slave);
 		bond_info->unbalanced_load += skb->len;
 	}
 
 	if (tx_slave && SLAVE_IS_OK(tx_slave)) {
-		if (tx_slave != bond->curr_active_slave) {
+		if (tx_slave != rcu_dereference(bond->curr_active_slave)) {
 			memcpy(eth_data->h_source,
 			       tx_slave->dev->dev_addr,
 			       ETH_ALEN);
@@ -1449,8 +1479,6 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
 		}
 	}
 
-	read_unlock(&bond->curr_slave_lock);
-	read_unlock(&bond->lock);
 	if (res) {
 		/* no suitable interface, frame not sent */
 		kfree_skb(skb);
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 0bd04fb..3c3076e 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -464,6 +464,20 @@ static inline struct slave *bond_slave_has_mac(struct bonding *bond,
 	return NULL;
 }
 
+/* Caller must hold rcu_read_lock() for read */
+static inline struct slave *bond_slave_has_mac_rcu(struct bonding *bond,
+					       const u8 *mac)
+{
+	struct list_head *iter;
+	struct slave *tmp;
+
+	bond_for_each_slave_rcu(bond, tmp, iter)
+		if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
+			return tmp;
+
+	return NULL;
+}
+
 /* Check if the ip is present in arp ip list, or first free slot if ip == 0
  * Returns -1 if not found, index if found
  */
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH net-next v2 1/3] bonding: use RCU protection for 3ad xmit path
From: Ding Tianhong @ 2013-10-15  8:28 UTC (permalink / raw)
  To: Jay Vosburgh, Andy Gospodarek, David S. Miller,
	Nikolay Aleksandrov, Veaceslav Falico, Netdev

The commit 278b20837511776dc9d5f6ee1c7fabd5479838bb
(bonding: initial RCU conversion) has convert the roundrobin,
active-backup, broadcast and xor xmit path to rcu protection,
the performance will be better for these mode, so this time,
convert xmit path for 3ad mode.

Suggested-by: Nikolay Aleksandrov <nikolay@redhat.com>
Suggested-by: Veaceslav Falico <vfalico@redhat.com>
Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Cc: Nikolay Aleksandrov <nikolay@redhat.com>
Cc: Veaceslav Falico <vfalico@redhat.com>
---
 drivers/net/bonding/bond_3ad.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index ea3e64e..187b1b7 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2344,7 +2344,7 @@ int __bond_3ad_get_active_agg_info(struct bonding *bond,
 	struct slave *slave;
 	struct port *port;
 
-	bond_for_each_slave(bond, slave, iter) {
+	bond_for_each_slave_rcu(bond, slave, iter) {
 		port = &(SLAVE_AD_INFO(slave).port);
 		if (port->aggregator && port->aggregator->is_active) {
 			aggregator = port->aggregator;
@@ -2369,9 +2369,9 @@ int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info)
 {
 	int ret;
 
-	read_lock(&bond->lock);
+	rcu_read_lock();
 	ret = __bond_3ad_get_active_agg_info(bond, ad_info);
-	read_unlock(&bond->lock);
+	rcu_read_unlock();
 
 	return ret;
 }
@@ -2388,7 +2388,6 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
 	int res = 1;
 	int agg_id;
 
-	read_lock(&bond->lock);
 	if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
 		pr_debug("%s: Error: __bond_3ad_get_active_agg_info failed\n",
 			 dev->name);
@@ -2406,7 +2405,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
 	slave_agg_no = bond_xmit_hash(bond, skb, slaves_in_agg);
 	first_ok_slave = NULL;
 
-	bond_for_each_slave(bond, slave, iter) {
+	bond_for_each_slave_rcu(bond, slave, iter) {
 		agg = SLAVE_AD_INFO(slave).port.aggregator;
 		if (!agg || agg->aggregator_identifier != agg_id)
 			continue;
@@ -2436,7 +2435,6 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
 		res = bond_dev_queue_xmit(bond, skb, first_ok_slave->dev);
 
 out:
-	read_unlock(&bond->lock);
 	if (res) {
 		/* no suitable interface, frame not sent */
 		kfree_skb(skb);
-- 
1.8.2.1

^ permalink raw reply related

* [PATCH net-next v2 0/3] bonding: patchset for rcu use in bonding
From: Ding Tianhong @ 2013-10-15  8:28 UTC (permalink / raw)
  To: Jay Vosburgh, Andy Gospodarek, David S. Miller,
	Nikolay Aleksandrov, Veaceslav Falico, Netdev

Hi:

The Patch Set convert the xmit of 3ad and alb mode to use rcu lock.
dd rtnl lock and remove read lock for bond sysfs.

v2 because the bond_for_each_slave_rcu without rcu_read_lock() will occurs one warming, so
add new function for alb xmit path to avoid warming.

Ding Tianhong (3):
Wang Yufen (1):
Yang Yingliang (1):
  bonding: use RCU protection for 3ad xmit path
  bonding: use RCU protection for alb xmit path
  bonding: add rtnl lock and remove read lock for bond sysfs

 drivers/net/bonding/bond_3ad.c   | 10 +++----
 drivers/net/bonding/bond_alb.c   | 58 +++++++++++++++++++++++++++++-----------
 drivers/net/bonding/bond_sysfs.c | 30 ++++++++++++---------
 drivers/net/bonding/bonding.h    | 14 ++++++++++
 4 files changed, 78 insertions(+), 34 deletions(-)

-- 
1.8.2.1

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox