linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: Remove unnecessary intermediate variables
@ 2020-08-22  2:04 Jianlin Lv
  2020-08-22 19:33 ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Jianlin Lv @ 2020-08-22  2:04 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, Song.Zhu, Jianlin.Lv, linux-kernel

It is not necessary to use src/dst as an intermediate variable for
assignment operation; Delete src/dst intermediate variables to avoid
unnecessary variable declarations.

Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
---
 drivers/net/vxlan.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index b9fefe27e3e8..c00ca01ebe76 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2728,12 +2728,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 			goto tx_error;
 		} else if (err) {
 			if (info) {
-				struct in_addr src, dst;
-
-				src = remote_ip.sin.sin_addr;
-				dst = local_ip.sin.sin_addr;
-				info->key.u.ipv4.src = src.s_addr;
-				info->key.u.ipv4.dst = dst.s_addr;
+				info->key.u.ipv4.src = remote_ip.sin.sin_addr.s_addr;
+				info->key.u.ipv4.dst = local_ip.sin.sin_addr.s_addr;
 			}
 			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
 			dst_release(ndst);
@@ -2784,12 +2780,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 			goto tx_error;
 		} else if (err) {
 			if (info) {
-				struct in6_addr src, dst;
-
-				src = remote_ip.sin6.sin6_addr;
-				dst = local_ip.sin6.sin6_addr;
-				info->key.u.ipv6.src = src;
-				info->key.u.ipv6.dst = dst;
+				info->key.u.ipv6.src = remote_ip.sin6.sin6_addr;
+				info->key.u.ipv6.dst = local_ip.sin6.sin6_addr;
 			}
 
 			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
-- 
2.17.1


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

* Re: [PATCH net-next] net: Remove unnecessary intermediate variables
  2020-08-22  2:04 [PATCH net-next] net: Remove unnecessary intermediate variables Jianlin Lv
@ 2020-08-22 19:33 ` David Miller
  2020-08-22 20:39   ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-08-22 19:33 UTC (permalink / raw)
  To: Jianlin.Lv; +Cc: netdev, kuba, Song.Zhu, linux-kernel

From: Jianlin Lv <Jianlin.Lv@arm.com>
Date: Sat, 22 Aug 2020 10:04:31 +0800

> It is not necessary to use src/dst as an intermediate variable for
> assignment operation; Delete src/dst intermediate variables to avoid
> unnecessary variable declarations.
> 
> Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>

It keeps the line lengths within reasonable length, so these local
variables are fine.

Also, the appropriate subsystem prefix for this patch should be "vxlan: "
not "net: " in your Subject line.  If someone is skimming the shortlog
in 'git' how will they tell where exactly in the networking your change
is being made?

Anyways, I'm not applying this, thanks.

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

* Re: [PATCH net-next] net: Remove unnecessary intermediate variables
  2020-08-22 19:33 ` David Miller
@ 2020-08-22 20:39   ` Joe Perches
  2020-08-22 20:59     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2020-08-22 20:39 UTC (permalink / raw)
  To: David Miller, Jianlin.Lv; +Cc: netdev, kuba, Song.Zhu, linux-kernel

On Sat, 2020-08-22 at 12:33 -0700, David Miller wrote:
> From: Jianlin Lv <Jianlin.Lv@arm.com>
> Date: Sat, 22 Aug 2020 10:04:31 +0800
> 
> > It is not necessary to use src/dst as an intermediate variable for
> > assignment operation; Delete src/dst intermediate variables to avoid
> > unnecessary variable declarations.
> > 
> > Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
> 
> It keeps the line lengths within reasonable length, so these local
> variables are fine.
> 
> Also, the appropriate subsystem prefix for this patch should be "vxlan: "
> not "net: " in your Subject line.  If someone is skimming the shortlog
> in 'git' how will they tell where exactly in the networking your change
> is being made?
> 
> Anyways, I'm not applying this, thanks.

It _might_ be slightly faster to use inlines
instead so there's less copy of 16 byte structs
on the ipv6 side.

It's slightly smaller object code.
---
 drivers/net/vxlan.c | 46 ++++++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index b9fefe27e3e8..e0ea246b3678 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -95,7 +95,25 @@ static inline bool vxlan_collect_metadata(struct vxlan_sock *vs)
 	       ip_tunnel_collect_metadata();
 }
 
+static __always_inline
+void vxlan_use_v4_addrs(struct ip_tunnel_info *info,
+			union vxlan_addr *remote_ip,
+			union vxlan_addr *local_ip)
+{
+	info->key.u.ipv4.src = remote_ip->sin.sin_addr.s_addr;
+	info->key.u.ipv4.dst = local_ip->sin.sin_addr.s_addr;
+}
+
 #if IS_ENABLED(CONFIG_IPV6)
+static __always_inline
+void vxlan_use_v6_addrs(struct ip_tunnel_info *info,
+			union vxlan_addr *remote_ip,
+			union vxlan_addr *local_ip)
+{
+	info->key.u.ipv6.src = remote_ip->sin6.sin6_addr;
+	info->key.u.ipv6.dst = local_ip->sin6.sin6_addr;
+}
+
 static inline
 bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
 {
@@ -2724,17 +2742,11 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		ndst = &rt->dst;
 		err = skb_tunnel_check_pmtu(skb, ndst, VXLAN_HEADROOM,
 					    netif_is_any_bridge_port(dev));
-		if (err < 0) {
+		if (err < 0)
 			goto tx_error;
-		} else if (err) {
-			if (info) {
-				struct in_addr src, dst;
-
-				src = remote_ip.sin.sin_addr;
-				dst = local_ip.sin.sin_addr;
-				info->key.u.ipv4.src = src.s_addr;
-				info->key.u.ipv4.dst = dst.s_addr;
-			}
+		if (err) {	/* newly built encapsulation length */
+			if (info)
+				vxlan_use_v4_addrs(info, &remote_ip, &local_ip);
 			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
 			dst_release(ndst);
 			goto out_unlock;
@@ -2780,17 +2792,11 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 
 		err = skb_tunnel_check_pmtu(skb, ndst, VXLAN6_HEADROOM,
 					    netif_is_any_bridge_port(dev));
-		if (err < 0) {
+		if (err < 0)
 			goto tx_error;
-		} else if (err) {
-			if (info) {
-				struct in6_addr src, dst;
-
-				src = remote_ip.sin6.sin6_addr;
-				dst = local_ip.sin6.sin6_addr;
-				info->key.u.ipv6.src = src;
-				info->key.u.ipv6.dst = dst;
-			}
+		if (err) {	/* newly built encapsulation length */
+			if (info)
+				vxlan_use_v6_addrs(info, &remote_ip, &local_ip);
 
 			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
 			dst_release(ndst);



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

* Re: [PATCH net-next] net: Remove unnecessary intermediate variables
  2020-08-22 20:39   ` Joe Perches
@ 2020-08-22 20:59     ` David Miller
  2020-08-22 21:03       ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-08-22 20:59 UTC (permalink / raw)
  To: joe; +Cc: Jianlin.Lv, netdev, kuba, Song.Zhu, linux-kernel

From: Joe Perches <joe@perches.com>
Date: Sat, 22 Aug 2020 13:39:28 -0700

> It _might_ be slightly faster to use inlines

We are not using the inline directive in foo.c files and are letting
the compiler decide.

Please don't give out advice like this.

Thank you.

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

* Re: [PATCH net-next] net: Remove unnecessary intermediate variables
  2020-08-22 20:59     ` David Miller
@ 2020-08-22 21:03       ` Joe Perches
  2020-08-22 21:07         ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2020-08-22 21:03 UTC (permalink / raw)
  To: David Miller; +Cc: Jianlin.Lv, netdev, kuba, Song.Zhu, linux-kernel

On Sat, 2020-08-22 at 13:59 -0700, David Miller wrote:
> From: Joe Perches <joe@perches.com>
> Date: Sat, 22 Aug 2020 13:39:28 -0700
> 
> > It _might_ be slightly faster to use inlines
> 
> We are not using the inline directive in foo.c files and are letting
> the compiler decide.
> 
> Please don't give out advice like this.

Actually, I checked with and without inline
before posting the proposal.

The compiler didn't inline the code without it.
Not even with just static inline.
For gcc 9.3 only the __always_inline did.
That's the only version I checked.




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

* Re: [PATCH net-next] net: Remove unnecessary intermediate variables
  2020-08-22 21:03       ` Joe Perches
@ 2020-08-22 21:07         ` David Miller
  2020-08-22 21:20           ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-08-22 21:07 UTC (permalink / raw)
  To: joe; +Cc: Jianlin.Lv, netdev, kuba, Song.Zhu, linux-kernel

From: Joe Perches <joe@perches.com>
Date: Sat, 22 Aug 2020 14:03:31 -0700

> The compiler didn't inline the code without it.

Then the compiler had a good reason for doing so, or it's a compiler
bug that should be reported.

I would reject any patch that added inline to a foo.c file, so unless
you want to make suggestions that will cause a contributor's patch to
be rejected, I'd suggest you not recommend inline usage in this way.

Thank you.

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

* Re: [PATCH net-next] net: Remove unnecessary intermediate variables
  2020-08-22 21:07         ` David Miller
@ 2020-08-22 21:20           ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2020-08-22 21:20 UTC (permalink / raw)
  To: David Miller; +Cc: Jianlin.Lv, netdev, kuba, Song.Zhu, linux-kernel

On Sat, 2020-08-22 at 14:07 -0700, David Miller wrote:
> From: Joe Perches <joe@perches.com>
> Date: Sat, 22 Aug 2020 14:03:31 -0700
> 
> > The compiler didn't inline the code without it.
> 
> Then the compiler had a good reason for doing so,

The "good" word choice there is slightly dubious.
Compilers make bad decisions all the time.

> or it's a compiler bug that should be reported.

<shrug>

Or just behavioral changes between versions, or
even just random compiler decisions that causes
known unrepeatable compilation output.

That happens all the time.

If you want it just as static without the
inline/__always_inline marking, let me know.



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

end of thread, other threads:[~2020-08-22 21:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22  2:04 [PATCH net-next] net: Remove unnecessary intermediate variables Jianlin Lv
2020-08-22 19:33 ` David Miller
2020-08-22 20:39   ` Joe Perches
2020-08-22 20:59     ` David Miller
2020-08-22 21:03       ` Joe Perches
2020-08-22 21:07         ` David Miller
2020-08-22 21:20           ` Joe Perches

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