[PATCH net-next] ipv4: avoid a test in ip_rt_put()

Subsystems: networking [general], networking [ipv4/ipv6], the rest

STALE5086d

3 messages, 3 authors, 2012-11-03 · open the first message on its own page

[PATCH net-next] ipv4: avoid a test in ip_rt_put()

From: Eric Dumazet <hidden>
Date: 2012-10-29 08:33:27

From: Eric Dumazet <redacted>

We can save a test in ip_rt_put(), considering dst_release() accepts
a NULL parameter, and dst is first element in rtable.

Add a BUILD_BUG_ON() to catch any change that could break this
assertion.

Signed-off-by: Eric Dumazet <redacted>
Cc: Cong Wang <redacted>
---
 include/net/route.h |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/include/net/route.h b/include/net/route.h
index bc40b63..2ea40c1 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -198,10 +198,13 @@ struct in_ifaddr;
 extern void fib_add_ifaddr(struct in_ifaddr *);
 extern void fib_del_ifaddr(struct in_ifaddr *, struct in_ifaddr *);
 
-static inline void ip_rt_put(struct rtable * rt)
+static inline void ip_rt_put(struct rtable *rt)
 {
-	if (rt)
-		dst_release(&rt->dst);
+	/* dst_release() accepts a NULL parameter.
+	 * We rely on dst being first structure in struct rtable
+	 */
+	BUILD_BUG_ON(offsetof(struct rtable, dst) != 0);
+	dst_release(&rt->dst);
 }
 
 #define IPTOS_RT_MASK	(IPTOS_TOS_MASK & ~3)

Re: [PATCH net-next] ipv4: avoid a test in ip_rt_put()

From: Cong Wang <hidden>
Date: 2012-10-29 09:09:11

On Mon, 2012-10-29 at 09:33 +0100, Eric Dumazet wrote:
From: Eric Dumazet <redacted>

We can save a test in ip_rt_put(), considering dst_release() accepts
a NULL parameter, and dst is first element in rtable.

Add a BUILD_BUG_ON() to catch any change that could break this
assertion.

Signed-off-by: Eric Dumazet <redacted>
Cc: Cong Wang <redacted>
Acked-by: Cong Wang <redacted>

Thanks!

Re: [PATCH net-next] ipv4: avoid a test in ip_rt_put()

From: David Miller <davem@davemloft.net>
Date: 2012-11-03 19:00:09

From: Cong Wang <redacted>
Date: Mon, 29 Oct 2012 17:09:06 +0800
On Mon, 2012-10-29 at 09:33 +0100, Eric Dumazet wrote:
quoted
From: Eric Dumazet <redacted>

We can save a test in ip_rt_put(), considering dst_release() accepts
a NULL parameter, and dst is first element in rtable.

Add a BUILD_BUG_ON() to catch any change that could break this
assertion.

Signed-off-by: Eric Dumazet <redacted>
Cc: Cong Wang <redacted>
Acked-by: Cong Wang <redacted>
Applied.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help