list_for_each_rcu must die: networking
[firefly-linux-kernel-4.4.55.git] / net / ipv6 / af_inet6.c
index 6b39af1acb5e373b2e91f79ee670ab09b95b34e2..60461ad7fa6ff0deaad6d6d27f463594ae0d7825 100644 (file)
@@ -59,9 +59,7 @@
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
-#ifdef CONFIG_IPV6_MROUTE
 #include <linux/mroute6.h>
-#endif
 
 MODULE_AUTHOR("Cast of dozens");
 MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
@@ -85,7 +83,6 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol)
        struct inet_sock *inet;
        struct ipv6_pinfo *np;
        struct sock *sk;
-       struct list_head *p;
        struct inet_protosw *answer;
        struct proto *answer_prot;
        unsigned char answer_flags;
@@ -99,13 +96,12 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol)
                build_ehash_secret();
 
        /* Look for the requested type/protocol pair. */
-       answer = NULL;
 lookup_protocol:
        err = -ESOCKTNOSUPPORT;
        rcu_read_lock();
-       list_for_each_rcu(p, &inetsw6[sock->type]) {
-               answer = list_entry(p, struct inet_protosw, list);
+       list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) {
 
+               err = 0;
                /* Check the non-wild match. */
                if (protocol == answer->protocol) {
                        if (protocol != IPPROTO_IP)
@@ -120,10 +116,9 @@ lookup_protocol:
                                break;
                }
                err = -EPROTONOSUPPORT;
-               answer = NULL;
        }
 
-       if (!answer) {
+       if (err) {
                if (try_loading_module < 2) {
                        rcu_read_unlock();
                        /*
@@ -952,11 +947,9 @@ static int __init inet6_init(void)
        err = icmpv6_init();
        if (err)
                goto icmp_fail;
-#ifdef CONFIG_IPV6_MROUTE
        err = ip6_mr_init();
        if (err)
                goto ipmr_fail;
-#endif
        err = ndisc_init();
        if (err)
                goto ndisc_fail;
@@ -1059,10 +1052,8 @@ netfilter_fail:
 igmp_fail:
        ndisc_cleanup();
 ndisc_fail:
-#ifdef CONFIG_IPV6_MROUTE
        ip6_mr_cleanup();
 ipmr_fail:
-#endif
        icmpv6_cleanup();
 icmp_fail:
        unregister_pernet_subsys(&inet6_net_ops);
@@ -1117,9 +1108,7 @@ static void __exit inet6_exit(void)
        ipv6_netfilter_fini();
        igmp6_cleanup();
        ndisc_cleanup();
-#ifdef CONFIG_IPV6_MROUTE
        ip6_mr_cleanup();
-#endif
        icmpv6_cleanup();
        rawv6_exit();