lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 15 Oct 2013 19:45:11 +0800
From:	Kefeng Wang <wangkefeng.wang@...wei.com>
To:	<linux-kernel@...r.kernel.org>
CC:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	"David S. Miller" <davem@...emloft.net>,
	Pablo Neira Ayuso <pablo@...filter.org>,
	"Stephen Hemminger" <stephen@...workplumber.org>,
	Johannes Berg <johannes@...solutions.net>,
	"John W. Linville" <linville@...driver.com>,
	Stanislaw Gruszka <sgruszka@...hat.com>,
	Johannes Berg <johannes.berg@...el.com>,
	Francois Romieu <romieu@...zoreil.com>,
	"Ben Hutchings" <bhutchings@...arflare.com>,
	Chas Williams <chas@....nrl.navy.mil>,
	Marc Kleine-Budde <mkl@...gutronix.de>,
	Samuel Ortiz <samuel@...tiz.org>,
	Paul Mackerras <paulus@...ba.org>,
	Oliver Neukum <oneukum@...e.de>,
	Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>,
	"Boris Ostrovsky" <boris.ostrovsky@...cle.com>,
	David Vrabel <david.vrabel@...rix.com>,
	Rusty Russell <rusty@...tcorp.com.au>,
	"Michael S. Tsirkin" <mst@...hat.com>, <netfilter@...r.kernel.org>,
	<netdev@...r.kernel.org>, <linux-wireless@...r.kernel.org>,
	<guohanjun@...wei.com>
Subject: [PATCH 15/18] net: xen: use wrapper functions of net_ratelimit() to simplify code

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

Signed-off-by: Kefeng Wang <wangkefeng.wang@...wei.com>
---
 drivers/net/xen-netback/netback.c | 21 +++++++++------------
 drivers/net/xen-netfront.c        | 27 +++++++++------------------
 2 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index f3e591c..bceb2ad 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -776,10 +776,9 @@ static int xenvif_count_requests(struct xenvif *vif,
 		 * dropped
 		 */
 		if (!drop_err && slots >= XEN_NETBK_LEGACY_SLOTS_MAX) {
-			if (net_ratelimit())
-				netdev_dbg(vif->dev,
-					   "Too many slots (%d) exceeding limit (%d), dropping packet\n",
-					   slots, XEN_NETBK_LEGACY_SLOTS_MAX);
+			net_ratelimited_function(netdev_dbg, vif->dev,
+				"Too many slots (%d) exceeding limit (%d), dropping packet\n",
+				slots, XEN_NETBK_LEGACY_SLOTS_MAX);
 			drop_err = -E2BIG;
 		}
 
@@ -799,10 +798,9 @@ static int xenvif_count_requests(struct xenvif *vif,
 		 * Consume all slots and drop the packet.
 		 */
 		if (!drop_err && txp->size > first->size) {
-			if (net_ratelimit())
-				netdev_dbg(vif->dev,
-					   "Invalid tx request, slot size %u > remaining size %u\n",
-					   txp->size, first->size);
+			net_ratelimited_function(netdev_dbg, vif->dev,
+				"Invalid tx request, slot size %u > remaining size %u\n",
+				txp->size, first->size);
 			drop_err = -EIO;
 		}
 
@@ -1170,10 +1168,9 @@ static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
 		}
 		break;
 	default:
-		if (net_ratelimit())
-			netdev_err(vif->dev,
-				   "Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
-				   iph->protocol);
+		net_ratelimited_function(netdev_err, vif->dev,
+			"Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
+			iph->protocol);
 		goto out;
 	}
 
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 36808bf..11eeef1 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -690,8 +690,7 @@ static int xennet_get_extras(struct netfront_info *np,
 		grant_ref_t ref;
 
 		if (unlikely(cons + 1 == rp)) {
-			if (net_ratelimit())
-				dev_warn(dev, "Missing extra info\n");
+			net_ratelimited_function(dev_warn, dev, "Missing extra info\n");
 			err = -EBADR;
 			break;
 		}
@@ -701,8 +700,7 @@ static int xennet_get_extras(struct netfront_info *np,
 
 		if (unlikely(!extra->type ||
 			     extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
-			if (net_ratelimit())
-				dev_warn(dev, "Invalid extra type: %d\n",
+			net_ratelimited_function(dev_warn, dev, "Invalid extra type: %d\n",
 					extra->type);
 			err = -EINVAL;
 		} else {
@@ -742,8 +740,7 @@ static int xennet_get_responses(struct netfront_info *np,
 	for (;;) {
 		if (unlikely(rx->status < 0 ||
 			     rx->offset + rx->status > PAGE_SIZE)) {
-			if (net_ratelimit())
-				dev_warn(dev, "rx->offset: %x, size: %u\n",
+			net_ratelimited_function(dev_warn, dev, "rx->offset: %x, size: %u\n",
 					 rx->offset, rx->status);
 			xennet_move_rx_slot(np, skb, ref);
 			err = -EINVAL;
@@ -756,8 +753,7 @@ static int xennet_get_responses(struct netfront_info *np,
 		 * situation to the system controller to reboot the backend.
 		 */
 		if (ref == GRANT_INVALID_REF) {
-			if (net_ratelimit())
-				dev_warn(dev, "Bad rx response id %d.\n",
+			net_ratelimited_function(dev_warn, dev, "Bad rx response id %d.\n",
 					 rx->id);
 			err = -EINVAL;
 			goto next;
@@ -775,8 +771,7 @@ next:
 			break;
 
 		if (cons + slots == rp) {
-			if (net_ratelimit())
-				dev_warn(dev, "Need more slots\n");
+			net_ratelimited_function(dev_warn, dev, "Need more slots\n");
 			err = -ENOENT;
 			break;
 		}
@@ -788,8 +783,7 @@ next:
 	}
 
 	if (unlikely(slots > max)) {
-		if (net_ratelimit())
-			dev_warn(dev, "Too many slots\n");
+		net_ratelimited_function(dev_warn, dev, "Too many slots\n");
 		err = -E2BIG;
 	}
 
@@ -803,15 +797,13 @@ static int xennet_set_skb_gso(struct sk_buff *skb,
 			      struct xen_netif_extra_info *gso)
 {
 	if (!gso->u.gso.size) {
-		if (net_ratelimit())
-			pr_warn("GSO size must not be zero\n");
+		net_warn_ratelimited("GSO size must not be zero\n");
 		return -EINVAL;
 	}
 
 	/* Currently only TCPv4 S.O. is supported. */
 	if (gso->u.gso.type != XEN_NETIF_GSO_TYPE_TCPV4) {
-		if (net_ratelimit())
-			pr_warn("Bad GSO type %d\n", gso->u.gso.type);
+		net_warn_ratelimited("Bad GSO type %d\n", gso->u.gso.type);
 		return -EINVAL;
 	}
 
@@ -910,8 +902,7 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
 		}
 		break;
 	default:
-		if (net_ratelimit())
-			pr_err("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
+		net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
 			       iph->protocol);
 		goto out;
 	}
-- 
1.8.2.1


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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ