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] [day] [month] [year] [list]
Date:   Tue, 23 Mar 2021 08:45:52 -0600
From:   David Ahern <dsahern@...il.com>
To:     Yejune Deng <yejune.deng@...il.com>, davem@...emloft.net,
        yoshfuji@...ux-ipv6.org, dsahern@...nel.org, kuba@...nel.org
Cc:     netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: ipv4: route.c: Remove unnecessary {else} if()

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@...il.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ