mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunsheng Lin <linyunsheng@huawei.com>
To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
	<pabeni@redhat.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH net-next] ipvlan: minor optimization for ipvlan outbound process
Date: Wed, 2 Nov 2022 10:15:49 +0800	[thread overview]
Message-ID: <20221102021549.12213-1-linyunsheng@huawei.com> (raw)

Avoid some local variable initialization and remove some
redundant assignment in ipvlan outbound process.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
---
 drivers/net/ipvlan/ipvlan_core.c | 56 +++++++++++++++-----------------
 1 file changed, 26 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c
index bb1c298c1e78..2b715035380b 100644
--- a/drivers/net/ipvlan/ipvlan_core.c
+++ b/drivers/net/ipvlan/ipvlan_core.c
@@ -417,7 +417,7 @@ static int ipvlan_process_v4_outbound(struct sk_buff *skb)
 	struct net_device *dev = skb->dev;
 	struct net *net = dev_net(dev);
 	struct rtable *rt;
-	int err, ret = NET_XMIT_DROP;
+	int err;
 	struct flowi4 fl4 = {
 		.flowi4_oif = dev->ifindex,
 		.flowi4_tos = RT_TOS(ip4h->tos),
@@ -438,15 +438,14 @@ static int ipvlan_process_v4_outbound(struct sk_buff *skb)
 	skb_dst_set(skb, &rt->dst);
 	err = ip_local_out(net, skb->sk, skb);
 	if (unlikely(net_xmit_eval(err)))
-		dev->stats.tx_errors++;
-	else
-		ret = NET_XMIT_SUCCESS;
-	goto out;
+		goto tx_errors_inc;
+
+	return NET_XMIT_SUCCESS;
 err:
-	dev->stats.tx_errors++;
 	kfree_skb(skb);
-out:
-	return ret;
+tx_errors_inc:
+	dev->stats.tx_errors++;
+	return NET_XMIT_DROP;
 }
 
 #if IS_ENABLED(CONFIG_IPV6)
@@ -456,7 +455,7 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb)
 	struct net_device *dev = skb->dev;
 	struct net *net = dev_net(dev);
 	struct dst_entry *dst;
-	int err, ret = NET_XMIT_DROP;
+	int err;
 	struct flowi6 fl6 = {
 		.flowi6_oif = dev->ifindex,
 		.daddr = ip6h->daddr,
@@ -469,22 +468,23 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb)
 
 	dst = ip6_route_output(net, NULL, &fl6);
 	if (dst->error) {
-		ret = dst->error;
+		err = dst->error;
 		dst_release(dst);
 		goto err;
 	}
 	skb_dst_set(skb, dst);
 	err = ip6_local_out(net, skb->sk, skb);
-	if (unlikely(net_xmit_eval(err)))
-		dev->stats.tx_errors++;
-	else
-		ret = NET_XMIT_SUCCESS;
-	goto out;
+	if (unlikely(net_xmit_eval(err))) {
+		err = NET_XMIT_DROP;
+		goto tx_errors_inc;
+	}
+
+	return NET_XMIT_SUCCESS;
 err:
-	dev->stats.tx_errors++;
 	kfree_skb(skb);
-out:
-	return ret;
+tx_errors_inc:
+	dev->stats.tx_errors++;
+	return err;
 }
 #else
 static int ipvlan_process_v6_outbound(struct sk_buff *skb)
@@ -495,8 +495,6 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb)
 
 static int ipvlan_process_outbound(struct sk_buff *skb)
 {
-	int ret = NET_XMIT_DROP;
-
 	/* The ipvlan is a pseudo-L2 device, so the packets that we receive
 	 * will have L2; which need to discarded and processed further
 	 * in the net-ns of the main-device.
@@ -511,7 +509,7 @@ static int ipvlan_process_outbound(struct sk_buff *skb)
 				"Dropped {multi|broad}cast of type=[%x]\n",
 				ntohs(skb->protocol));
 			kfree_skb(skb);
-			goto out;
+			return NET_XMIT_DROP;
 		}
 
 		skb_pull(skb, sizeof(*ethh));
@@ -520,16 +518,14 @@ static int ipvlan_process_outbound(struct sk_buff *skb)
 	}
 
 	if (skb->protocol == htons(ETH_P_IPV6))
-		ret = ipvlan_process_v6_outbound(skb);
+		return ipvlan_process_v6_outbound(skb);
 	else if (skb->protocol == htons(ETH_P_IP))
-		ret = ipvlan_process_v4_outbound(skb);
-	else {
-		pr_warn_ratelimited("Dropped outbound packet type=%x\n",
-				    ntohs(skb->protocol));
-		kfree_skb(skb);
-	}
-out:
-	return ret;
+		return ipvlan_process_v4_outbound(skb);
+
+	pr_warn_ratelimited("Dropped outbound packet type=%x\n",
+			    ntohs(skb->protocol));
+	kfree_skb(skb);
+	return NET_XMIT_DROP;
 }
 
 static void ipvlan_multicast_enqueue(struct ipvl_port *port,
-- 
2.33.0


             reply	other threads:[~2022-11-02  2:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02  2:15 Yunsheng Lin [this message]
2022-11-02  3:23 ` Eric Dumazet
2022-11-02  3:47   ` Yunsheng Lin
2022-11-02  4:06     ` Eric Dumazet

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20221102021549.12213-1-linyunsheng@huawei.com \
    --to=linyunsheng@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®