aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/proc/proc_net.c6
-rw-r--r--include/linux/proc_fs.h5
-rw-r--r--include/net/net_namespace.h12
-rw-r--r--net/core/dev.c6
-rw-r--r--net/core/dev_mcast.c6
-rw-r--r--net/netlink/af_netlink.c6
-rw-r--r--net/wireless/wext.c6
7 files changed, 39 insertions, 8 deletions
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index 358930a3142a..85cc8e8bb862 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -51,6 +51,12 @@ void proc_net_remove(struct net *net, const char *name)
51} 51}
52EXPORT_SYMBOL_GPL(proc_net_remove); 52EXPORT_SYMBOL_GPL(proc_net_remove);
53 53
54struct net *get_proc_net(const struct inode *inode)
55{
56 return maybe_get_net(PDE_NET(PDE(inode)));
57}
58EXPORT_SYMBOL_GPL(get_proc_net);
59
54static struct proc_dir_entry *proc_net_shadow; 60static struct proc_dir_entry *proc_net_shadow;
55 61
56static struct dentry *proc_net_shadow_dentry(struct dentry *parent, 62static struct dentry *proc_net_shadow_dentry(struct dentry *parent,
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 59646705f151..20741f668f7b 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -270,10 +270,7 @@ static inline struct net *PDE_NET(struct proc_dir_entry *pde)
270 return pde->parent->data; 270 return pde->parent->data;
271} 271}
272 272
273static inline struct net *PROC_NET(const struct inode *inode) 273struct net *get_proc_net(const struct inode *inode);
274{
275 return PDE_NET(PDE(inode));
276}
277 274
278struct proc_maps_private { 275struct proc_maps_private {
279 struct pid *pid; 276 struct pid *pid;
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)
46 return net; 46 return net;
47} 47}
48 48
49static inline struct net *maybe_get_net(struct net *net)
50{
51 /* Used when we know struct net exists but we
52 * aren't guaranteed a previous reference count
53 * exists. If the reference count is zero this
54 * function fails and returns NULL.
55 */
56 if (!atomic_inc_not_zero(&net->count))
57 net = NULL;
58 return net;
59}
60
49static inline void put_net(struct net *net) 61static inline void put_net(struct net *net)
50{ 62{
51 if (atomic_dec_and_test(&net->count)) 63 if (atomic_dec_and_test(&net->count))
diff --git a/net/core/dev.c b/net/core/dev.c
index d16dcab49c60..666c112efb55 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2464,7 +2464,11 @@ static int dev_seq_open(struct inode *inode, struct file *file)
2464 res = seq_open(file, &dev_seq_ops); 2464 res = seq_open(file, &dev_seq_ops);
2465 if (!res) { 2465 if (!res) {
2466 seq = file->private_data; 2466 seq = file->private_data;
2467 seq->private = get_net(PROC_NET(inode)); 2467 seq->private = get_proc_net(inode);
2468 if (!seq->private) {
2469 seq_release(inode, file);
2470 res = -ENXIO;
2471 }
2468 } 2472 }
2469 return res; 2473 return res;
2470} 2474}
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index 1c4f6198459b..896b0ca5aed7 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -246,7 +246,11 @@ static int dev_mc_seq_open(struct inode *inode, struct file *file)
246 res = seq_open(file, &dev_mc_seq_ops); 246 res = seq_open(file, &dev_mc_seq_ops);
247 if (!res) { 247 if (!res) {
248 seq = file->private_data; 248 seq = file->private_data;
249 seq->private = get_net(PROC_NET(inode)); 249 seq->private = get_proc_net(inode);
250 if (!seq->private) {
251 seq_release(inode, file);
252 res = -ENXIO;
253 }
250 } 254 }
251 return res; 255 return res;
252} 256}
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 3029f865cd61..dc9f8c2ab1d5 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1859,7 +1859,11 @@ static int netlink_seq_open(struct inode *inode, struct file *file)
1859 1859
1860 seq = file->private_data; 1860 seq = file->private_data;
1861 seq->private = iter; 1861 seq->private = iter;
1862 iter->net = get_net(PROC_NET(inode)); 1862 iter->net = get_proc_net(inode);
1863 if (!iter->net) {
1864 seq_release_private(inode, file);
1865 return -ENXIO;
1866 }
1863 return 0; 1867 return 0;
1864} 1868}
1865 1869
diff --git a/net/wireless/wext.c b/net/wireless/wext.c
index e8b3409d6c8b..85e5f9dd0d8e 100644
--- a/net/wireless/wext.c
+++ b/net/wireless/wext.c
@@ -678,7 +678,11 @@ static int wireless_seq_open(struct inode *inode, struct file *file)
678 res = seq_open(file, &wireless_seq_ops); 678 res = seq_open(file, &wireless_seq_ops);
679 if (!res) { 679 if (!res) {
680 seq = file->private_data; 680 seq = file->private_data;
681 seq->private = get_net(PROC_NET(inode)); 681 seq->private = get_proc_net(inode);
682 if (!seq->private) {
683 seq_release(inode, file);
684 res = -ENXIO;
685 }
682 } 686 }
683 return res; 687 return res;
684} 688}