Skip to content

Commit 6da025f

Browse files
edumazetdavem330
authored andcommitted
ipv4: avoid a test in ip_rt_put()
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 <[email protected]> Cc: Cong Wang <[email protected]> Acked-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b26ddd8 commit 6da025f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

include/net/route.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,13 @@ struct in_ifaddr;
198198
extern void fib_add_ifaddr(struct in_ifaddr *);
199199
extern void fib_del_ifaddr(struct in_ifaddr *, struct in_ifaddr *);
200200

201-
static inline void ip_rt_put(struct rtable * rt)
201+
static inline void ip_rt_put(struct rtable *rt)
202202
{
203-
if (rt)
204-
dst_release(&rt->dst);
203+
/* dst_release() accepts a NULL parameter.
204+
* We rely on dst being first structure in struct rtable
205+
*/
206+
BUILD_BUG_ON(offsetof(struct rtable, dst) != 0);
207+
dst_release(&rt->dst);
205208
}
206209

207210
#define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)

0 commit comments

Comments
 (0)