History

ipv6: fix sparse warning on rt6i_node

Commit c5cff8561d2d adds rcu grace period before freeing fib6_node. This generates a new sparse warning on rt->rt6i_node related code: net/ipv6/route.c:1394:30: error: incompatible types in comparison expression (different address spaces) ./include/net/ip6_fib.h:187:14: error: incompatible types in comparison expression (different address spaces) This commit adds "__rcu" tag for rt6i_node and makes sure corresponding rcu API is used for it. After this fix, sparse no longer generates the above warning.

Wei Wang committed 9 years ago

Commit 4e587ea1 parent 0f308684 files · +11 −7Browse files

Unified · Split

4 files
  1. include/net/ip6_fib.h +1 −1
  2. net/ipv6/addrconf.c +1 −1
  3. net/ipv6/ip6_fib.c +7 −4
  4. net/ipv6/route.c +2 −1
include/net/ip6_fib.h+1−1
@@ -105,7 +105,7 @@ struct rt6_info { · 104 unmodified lines
105105 * the same cache line.
106106 */
107107 struct fib6_table *rt6i_table;
108− struct fib6_node *rt6i_node;
108+ struct fib6_node __rcu *rt6i_node;
109109
110110 struct in6_addr rt6i_gateway;
111111
net/ipv6/addrconf.c+1−1
@@ -5556,7 +5556,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) · 5555 unmodified lines
55565556 * our DAD process, so we don't need
55575557 * to do it again
55585558 */
5559− if (!(ifp->rt->rt6i_node))
5559+ if (!rcu_access_pointer(ifp->rt->rt6i_node))
55605560 ip6_ins_rt(ifp->rt);
55615561 if (ifp->idev->cnf.forwarding)
55625562 addrconf_join_anycast(ifp);
net/ipv6/ip6_fib.c+7−4
@@ -889,7 +889,7 @@ add: · 888 unmodified lines
889889
890890 rt->dst.rt6_next = iter;
891891 *ins = rt;
892− rt->rt6i_node = fn;
892+ rcu_assign_pointer(rt->rt6i_node, fn);
893893 atomic_inc(&rt->rt6i_ref);
894894 if (!info->skip_notify)
895895 inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags);
@@ -915,7 +915,7 @@ add: · 19 unmodified lines
915915 return err;
916916
917917 *ins = rt;
918− rt->rt6i_node = fn;
918+ rcu_assign_pointer(rt->rt6i_node, fn);
919919 rt->dst.rt6_next = iter->dst.rt6_next;
920920 atomic_inc(&rt->rt6i_ref);
921921 if (!info->skip_notify)
@@ -1480,8 +1480,9 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp, · 558 unmodified lines
14801480
14811481 int fib6_del(struct rt6_info *rt, struct nl_info *info)
14821482 {
1483+ struct fib6_node *fn = rcu_dereference_protected(rt->rt6i_node,
1484+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
14831485 struct net *net = info->nl_net;
1484− struct fib6_node *fn = rt->rt6i_node;
14851486 struct rt6_info **rtp;
14861487
14871488 #if RT6_DEBUG >= 2
@@ -1670,7 +1671,9 @@ static int fib6_clean_node(struct fib6_walker *w) · 182 unmodified lines
16701671 if (res) {
16711672 #if RT6_DEBUG >= 2
16721673 pr_debug("%s: del failed: rt=%p@%p err=%d\n",
1673− __func__, rt, rt->rt6i_node, res);
1674+ __func__, rt,
1675+ rcu_access_pointer(rt->rt6i_node),
1676+ res);
16741677 #endif
16751678 continue;
16761679 }
net/ipv6/route.c+2−1
@@ -1383,7 +1383,8 @@ static void rt6_do_update_pmtu(struct rt6_info *rt, u32 mtu) · 1382 unmodified lines
13831383 static bool rt6_cache_allowed_for_pmtu(const struct rt6_info *rt)
13841384 {
13851385 return !(rt->rt6i_flags & RTF_CACHE) &&
1386− (rt->rt6i_flags & RTF_PCPU || rt->rt6i_node);
1386+ (rt->rt6i_flags & RTF_PCPU ||
1387+ rcu_access_pointer(rt->rt6i_node));
13871388 }
13881389
13891390 static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,