linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ipv4: route.c: Remove unnecessary {else} if()
@ 2021-03-23 10:20 Yejune Deng
  2021-03-23 14:45 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Yejune Deng @ 2021-03-23 10:20 UTC (permalink / raw)
  To: davem, yoshfuji, dsahern, kuba; +Cc: netdev, linux-kernel, yejune.deng

Put if and else if together, and remove unnecessary judgments, because
it's caller can make sure it is true. And add likely() in
ipv4_confirm_neigh().

Signed-off-by: Yejune Deng <yejune.deng@gmail.com>
---
 net/ipv4/route.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index fa68c2612252..f4ba07c5c1b1 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -440,7 +440,7 @@ static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)
 	struct net_device *dev = dst->dev;
 	const __be32 *pkey = daddr;
 
-	if (rt->rt_gw_family == AF_INET) {
+	if (likely(rt->rt_gw_family == AF_INET)) {
 		pkey = (const __be32 *)&rt->rt_gw4;
 	} else if (rt->rt_gw_family == AF_INET6) {
 		return __ipv6_confirm_neigh_stub(dev, &rt->rt_gw6);
@@ -814,19 +814,15 @@ static void ip_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_buf
 
 static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
 {
-	struct rtable *rt = (struct rtable *)dst;
+	struct rtable *rt = container_of(dst, struct rtable, dst);
 	struct dst_entry *ret = dst;
 
-	if (rt) {
-		if (dst->obsolete > 0) {
-			ip_rt_put(rt);
-			ret = NULL;
-		} else if ((rt->rt_flags & RTCF_REDIRECTED) ||
-			   rt->dst.expires) {
-			ip_rt_put(rt);
-			ret = NULL;
-		}
+	if (dst->obsolete > 0 || rt->dst.expires ||
+	    (rt->rt_flags & RTCF_REDIRECTED)) {
+		ip_rt_put(rt);
+		ret = NULL;
 	}
+
 	return ret;
 }
 
-- 
2.29.0


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

* Re: [PATCH] net: ipv4: route.c: Remove unnecessary {else} if()
  2021-03-23 10:20 [PATCH] net: ipv4: route.c: Remove unnecessary {else} if() Yejune Deng
@ 2021-03-23 14:45 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2021-03-23 14:45 UTC (permalink / raw)
  To: Yejune Deng, davem, yoshfuji, dsahern, kuba; +Cc: netdev, linux-kernel

subject line should have net-next as the target branch


On 3/23/21 4:20 AM, Yejune Deng wrote:
> Put if and else if together, and remove unnecessary judgments, because
> it's caller can make sure it is true. And add likely() in
> ipv4_confirm_neigh().
> 
> Signed-off-by: Yejune Deng <yejune.deng@gmail.com>
> ---
>  net/ipv4/route.c | 18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index fa68c2612252..f4ba07c5c1b1 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -440,7 +440,7 @@ static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)
>  	struct net_device *dev = dst->dev;
>  	const __be32 *pkey = daddr;
>  
> -	if (rt->rt_gw_family == AF_INET) {
> +	if (likely(rt->rt_gw_family == AF_INET)) {
>  		pkey = (const __be32 *)&rt->rt_gw4;
>  	} else if (rt->rt_gw_family == AF_INET6) {
>  		return __ipv6_confirm_neigh_stub(dev, &rt->rt_gw6);
> @@ -814,19 +814,15 @@ static void ip_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_buf
>  
>  static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
>  {
> -	struct rtable *rt = (struct rtable *)dst;
> +	struct rtable *rt = container_of(dst, struct rtable, dst);
>  	struct dst_entry *ret = dst;
>  
> -	if (rt) {
> -		if (dst->obsolete > 0) {
> -			ip_rt_put(rt);
> -			ret = NULL;
> -		} else if ((rt->rt_flags & RTCF_REDIRECTED) ||
> -			   rt->dst.expires) {
> -			ip_rt_put(rt);
> -			ret = NULL;
> -		}
> +	if (dst->obsolete > 0 || rt->dst.expires ||
> +	    (rt->rt_flags & RTCF_REDIRECTED)) {
> +		ip_rt_put(rt);
> +		ret = NULL;
>  	}
> +
>  	return ret;
>  }
>  
> 

This should be 2 separate patches since they are unrelated changes.

For the ipv4_negative_advice, the changelog should note that
negative_advice handler is only called when dst is non-NULL hence the
'if (rt)' check can be removed.

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

end of thread, other threads:[~2021-03-23 14:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 10:20 [PATCH] net: ipv4: route.c: Remove unnecessary {else} if() Yejune Deng
2021-03-23 14:45 ` David Ahern

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).