All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] net: ipv4: route.c: Remove unnecessary if()
@ 2021-03-24  3:10 Yejune Deng
  2021-03-25 14:36 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Yejune Deng @ 2021-03-24  3:10 UTC (permalink / raw)
  To: davem, yoshfuji, dsahern, kuba; +Cc: netdev, linux-kernel, yejune, Yejune Deng

negative_advice handler is only called when dst is non-NULL hence the
'if (rt)' check can be removed. 'if' and 'else if' can be merged together.
And use container_of() instead of (struct rtable *).

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

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 5762d9bc671c..f4ba07c5c1b1 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -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 2/2] net: ipv4: route.c: Remove unnecessary if()
  2021-03-24  3:10 [PATCH 2/2] net: ipv4: route.c: Remove unnecessary if() Yejune Deng
@ 2021-03-25 14:36 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2021-03-25 14:36 UTC (permalink / raw)
  To: Yejune Deng, davem, yoshfuji, dsahern, kuba; +Cc: netdev, linux-kernel, yejune

On 3/23/21 9:10 PM, Yejune Deng wrote:
> negative_advice handler is only called when dst is non-NULL hence the
> 'if (rt)' check can be removed. 'if' and 'else if' can be merged together.
> And use container_of() instead of (struct rtable *).
> 
> Signed-off-by: Yejune Deng <yejune.deng@gmail.com>
> ---
>  net/ipv4/route.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 


Reviewed-by: David Ahern <dsahern@kernel.org>

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

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

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.