net: ipv4: route.c: Remove unnecessary {else} if()
Subsystems (3)
PATCH 1/1 net: ipv4: route.c: Remove unnecessary {else} if()
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().
--- net/ipv4/route.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
net/ipv4/route.c +7 -11
@@ -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_bufstatic 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; }
Signature · 1 line
2.29.0
subject line should have net-next as the target branch
Quoted 39 lines · 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()inipv4_confirm_neigh().Signed-off-by Yejune Deng <[email protected]>--- net/ipv4/route.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)net/ipv4/route.c +2
-10@@ -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_bufstatic 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 ;
net/ipv4/route.c static void ip_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_buf · line 828
Quoted 10 lines
net/ipv4/route.c +5
-1- } +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.