[PATCH] net: ipv4: route.c: Remove unnecessary {else} if()

From: Yejune Deng
Date: Tue Mar 23 2021 - 06:21:16 EST


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@xxxxxxxxx>
---
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