Skip to content

Commit

Permalink
ipv4: avoid a test in ip_rt_put()
Browse files Browse the repository at this point in the history
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 <edumazet@google.com>
Cc: Cong Wang <amwang@redhat.com>
Acked-by: Cong Wang <amwang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Nov 3, 2012
1 parent b26ddd8 commit 6da025f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6da025f

Please sign in to comment.