]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - include/net/net_namespace.h
[NET]: Fix race when opening a proc file while a network namespace is exiting.
[linux-2.6-omap-h63xx.git] / include / net / net_namespace.h
index 3081b6ed35fe3930157e3e5c1289a544ef7a0a8e..ac8f8304094ed62e25c4f35eb1a9203fe89f386c 100644 (file)
@@ -46,6 +46,18 @@ static inline struct net *get_net(struct net *net)
        return net;
 }
 
+static inline struct net *maybe_get_net(struct net *net)
+{
+       /* Used when we know struct net exists but we
+        * aren't guaranteed a previous reference count
+        * exists.  If the reference count is zero this
+        * function fails and returns NULL.
+        */
+       if (!atomic_inc_not_zero(&net->count))
+               net = NULL;
+       return net;
+}
+
 static inline void put_net(struct net *net)
 {
        if (atomic_dec_and_test(&net->count))