* [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info
@ 2018-09-30 5:02 Li RongQing
2018-09-30 9:27 ` Li RongQing
2018-09-30 9:32 ` Stephen Hemminger
0 siblings, 2 replies; 5+ messages in thread
From: Li RongQing @ 2018-09-30 5:02 UTC (permalink / raw
To: netdev
we can save container_of computation and return dst directly,
since dst is always first member of struct rt6_info
Add a BUILD_BUG_ON() to catch any change that could break this
assertion.
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
include/net/ip6_route.h | 4 +++-
net/ipv6/route.c | 6 +++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 7b9c82de11cc..1f09298634cb 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -194,8 +194,10 @@ static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb)
const struct dst_entry *dst = skb_dst(skb);
const struct rt6_info *rt6 = NULL;
+ BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
+
if (dst)
- rt6 = container_of(dst, struct rt6_info, dst);
+ rt6 = (struct rt6_info *)dst;
return rt6;
}
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d28f83e01593..3fb8034fc2d0 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -217,7 +217,7 @@ static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,
struct sk_buff *skb,
const void *daddr)
{
- const struct rt6_info *rt = container_of(dst, struct rt6_info, dst);
+ const struct rt6_info *rt = (struct rt6_info *)dst;
return ip6_neigh_lookup(&rt->rt6i_gateway, dst->dev, skb, daddr);
}
@@ -2187,7 +2187,7 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie)
struct fib6_info *from;
struct rt6_info *rt;
- rt = container_of(dst, struct rt6_info, dst);
+ rt = (struct rt6_info *)dst;
rcu_read_lock();
@@ -4911,7 +4911,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
}
- rt = container_of(dst, struct rt6_info, dst);
+ rt = (struct rt6_info *)dst;
if (rt->dst.error) {
err = rt->dst.error;
ip6_rt_put(rt);
--
2.16.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info
2018-09-30 5:02 [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info Li RongQing
@ 2018-09-30 9:27 ` Li RongQing
2018-09-30 9:32 ` Stephen Hemminger
1 sibling, 0 replies; 5+ messages in thread
From: Li RongQing @ 2018-09-30 9:27 UTC (permalink / raw
To: Li RongQing; +Cc: netdev
> + BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
> +
please drop this patch, thanks
since BUILD_BUG_ON has been added in ip6_fib.h
include/net/ip6_fib.h: BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
-Li
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info
2018-09-30 5:02 [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info Li RongQing
2018-09-30 9:27 ` Li RongQing
@ 2018-09-30 9:32 ` Stephen Hemminger
2018-09-30 9:38 ` Li RongQing
1 sibling, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2018-09-30 9:32 UTC (permalink / raw
To: Li RongQing; +Cc: netdev
On Sun, 30 Sep 2018 13:02:52 +0800
Li RongQing <lirongqing@baidu.com> wrote:
> we can save container_of computation and return dst directly,
> since dst is always first member of struct rt6_info
>
> Add a BUILD_BUG_ON() to catch any change that could break this
> assertion.
>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
I don't understand why you are doing this? It is not going to be
faster (or safer) than container_of. container_of provides the
same functionality and is safe against position of the member
in the structure.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info
2018-09-30 9:32 ` Stephen Hemminger
@ 2018-09-30 9:38 ` Li RongQing
2018-09-30 15:29 ` David Ahern
0 siblings, 1 reply; 5+ messages in thread
From: Li RongQing @ 2018-09-30 9:38 UTC (permalink / raw
To: Stephen Hemminger; +Cc: Li RongQing, netdev
>
> I don't understand why you are doing this? It is not going to be
> faster (or safer) than container_of. container_of provides the
> same functionality and is safe against position of the member
> in the structure.
>
In fact, most places are converting dst to rt6_info directly, and only
few place uses container_of
net/ipv6/ip6_output.c: struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
net/ipv6/route.c: const struct rt6_info *rt = (struct rt6_info *)dst;
-Li
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info
2018-09-30 9:38 ` Li RongQing
@ 2018-09-30 15:29 ` David Ahern
0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2018-09-30 15:29 UTC (permalink / raw
To: Li RongQing, Stephen Hemminger; +Cc: Li RongQing, netdev
On 9/30/18 3:38 AM, Li RongQing wrote:
>>
>> I don't understand why you are doing this? It is not going to be
>> faster (or safer) than container_of. container_of provides the
>> same functionality and is safe against position of the member
>> in the structure.
>>
>
> In fact, most places are converting dst to rt6_info directly, and only
> few place uses container_of
>
>
> net/ipv6/ip6_output.c: struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
> net/ipv6/route.c: const struct rt6_info *rt = (struct rt6_info *)dst;
>
I am trying to convert all places to container_of rather than a
typecast. Please do not undo that
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-09-30 22:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-30 5:02 [PATCH][net-next] ipv6: drop container_of when convert dst to rt6_info Li RongQing
2018-09-30 9:27 ` Li RongQing
2018-09-30 9:32 ` Stephen Hemminger
2018-09-30 9:38 ` Li RongQing
2018-09-30 15:29 ` 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.