summaryrefslogtreecommitdiff
path: root/include/net/net_namespace.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/net_namespace.h')
-rw-r--r--include/net/net_namespace.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 3081b6ed35fe..ac8f8304094e 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -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))