]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - net/ipv6/protocol.c
Merge branch 'master' into csb1725
[mv-sheeva.git] / net / ipv6 / protocol.c
index 1fa3468f0f323782413c1931258c61aa9130f450..9a7978fdc02a5de453feb7c4ca1ea9c1e7652292 100644 (file)
 #include <linux/spinlock.h>
 #include <net/protocol.h>
 
-const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS];
-static DEFINE_SPINLOCK(inet6_proto_lock);
-
+const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly;
 
 int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol)
 {
-       int ret, hash = protocol & (MAX_INET_PROTOS - 1);
-
-       spin_lock_bh(&inet6_proto_lock);
-
-       if (inet6_protos[hash]) {
-               ret = -1;
-       } else {
-               inet6_protos[hash] = prot;
-               ret = 0;
-       }
-
-       spin_unlock_bh(&inet6_proto_lock);
+       int hash = protocol & (MAX_INET_PROTOS - 1);
 
-       return ret;
+       return !cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
+                       NULL, prot) ? 0 : -1;
 }
-
 EXPORT_SYMBOL(inet6_add_protocol);
 
 /*
@@ -57,20 +44,11 @@ int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol
 {
        int ret, hash = protocol & (MAX_INET_PROTOS - 1);
 
-       spin_lock_bh(&inet6_proto_lock);
-
-       if (inet6_protos[hash] != prot) {
-               ret = -1;
-       } else {
-               inet6_protos[hash] = NULL;
-               ret = 0;
-       }
-
-       spin_unlock_bh(&inet6_proto_lock);
+       ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
+                      prot, NULL) == prot) ? 0 : -1;
 
        synchronize_net();
 
        return ret;
 }
-
 EXPORT_SYMBOL(inet6_del_protocol);