Commit cf7732e4 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller

[NET]: Make core networking code use seq_open_private

This concerns the ipv4 and ipv6 code mostly, but also the netlink
and unix sockets.

The netlink code is an example of how to use the __seq_open_private()
call - it saves the net namespace on this private.
Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 39699037
...@@ -1378,24 +1378,8 @@ static const struct seq_operations arp_seq_ops = { ...@@ -1378,24 +1378,8 @@ static const struct seq_operations arp_seq_ops = {
static int arp_seq_open(struct inode *inode, struct file *file) static int arp_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &arp_seq_ops,
int rc = -ENOMEM; sizeof(struct neigh_seq_state));
struct neigh_seq_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &arp_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations arp_seq_fops = { static const struct file_operations arp_seq_fops = {
......
...@@ -1039,24 +1039,8 @@ static const struct seq_operations fib_seq_ops = { ...@@ -1039,24 +1039,8 @@ static const struct seq_operations fib_seq_ops = {
static int fib_seq_open(struct inode *inode, struct file *file) static int fib_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &fib_seq_ops,
int rc = -ENOMEM; sizeof(struct fib_iter_state));
struct fib_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &fib_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations fib_seq_fops = { static const struct file_operations fib_seq_fops = {
......
...@@ -2379,25 +2379,8 @@ static const struct seq_operations fib_trie_seq_ops = { ...@@ -2379,25 +2379,8 @@ static const struct seq_operations fib_trie_seq_ops = {
static int fib_trie_seq_open(struct inode *inode, struct file *file) static int fib_trie_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &fib_trie_seq_ops,
int rc = -ENOMEM; sizeof(struct fib_trie_iter));
struct fib_trie_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &fib_trie_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
memset(s, 0, sizeof(*s));
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations fib_trie_fops = { static const struct file_operations fib_trie_fops = {
...@@ -2500,25 +2483,8 @@ static const struct seq_operations fib_route_seq_ops = { ...@@ -2500,25 +2483,8 @@ static const struct seq_operations fib_route_seq_ops = {
static int fib_route_seq_open(struct inode *inode, struct file *file) static int fib_route_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &fib_route_seq_ops,
int rc = -ENOMEM; sizeof(struct fib_trie_iter));
struct fib_trie_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &fib_route_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
memset(s, 0, sizeof(*s));
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations fib_route_fops = { static const struct file_operations fib_route_fops = {
......
...@@ -2410,23 +2410,8 @@ static const struct seq_operations igmp_mc_seq_ops = { ...@@ -2410,23 +2410,8 @@ static const struct seq_operations igmp_mc_seq_ops = {
static int igmp_mc_seq_open(struct inode *inode, struct file *file) static int igmp_mc_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &igmp_mc_seq_ops,
int rc = -ENOMEM; sizeof(struct igmp_mc_iter_state));
struct igmp_mc_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &igmp_mc_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations igmp_mc_seq_fops = { static const struct file_operations igmp_mc_seq_fops = {
...@@ -2584,23 +2569,8 @@ static const struct seq_operations igmp_mcf_seq_ops = { ...@@ -2584,23 +2569,8 @@ static const struct seq_operations igmp_mcf_seq_ops = {
static int igmp_mcf_seq_open(struct inode *inode, struct file *file) static int igmp_mcf_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &igmp_mcf_seq_ops,
int rc = -ENOMEM; sizeof(struct igmp_mcf_iter_state));
struct igmp_mcf_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &igmp_mcf_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations igmp_mcf_seq_fops = { static const struct file_operations igmp_mcf_seq_fops = {
......
...@@ -1714,26 +1714,8 @@ static const struct seq_operations ipmr_vif_seq_ops = { ...@@ -1714,26 +1714,8 @@ static const struct seq_operations ipmr_vif_seq_ops = {
static int ipmr_vif_open(struct inode *inode, struct file *file) static int ipmr_vif_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &ipmr_vif_seq_ops,
int rc = -ENOMEM; sizeof(struct ipmr_vif_iter));
struct ipmr_vif_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &ipmr_vif_seq_ops);
if (rc)
goto out_kfree;
s->ct = 0;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations ipmr_vif_fops = { static const struct file_operations ipmr_vif_fops = {
...@@ -1877,25 +1859,8 @@ static const struct seq_operations ipmr_mfc_seq_ops = { ...@@ -1877,25 +1859,8 @@ static const struct seq_operations ipmr_mfc_seq_ops = {
static int ipmr_mfc_open(struct inode *inode, struct file *file) static int ipmr_mfc_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &ipmr_mfc_seq_ops,
int rc = -ENOMEM; sizeof(struct ipmr_mfc_iter));
struct ipmr_mfc_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &ipmr_mfc_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations ipmr_mfc_fops = { static const struct file_operations ipmr_mfc_fops = {
......
...@@ -1792,24 +1792,8 @@ static const struct seq_operations ip_vs_info_seq_ops = { ...@@ -1792,24 +1792,8 @@ static const struct seq_operations ip_vs_info_seq_ops = {
static int ip_vs_info_open(struct inode *inode, struct file *file) static int ip_vs_info_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &ip_vs_info_seq_ops,
int rc = -ENOMEM; sizeof(struct ip_vs_iter));
struct ip_vs_iter *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &ip_vs_info_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations ip_vs_info_fops = { static const struct file_operations ip_vs_info_fops = {
......
...@@ -902,24 +902,8 @@ static const struct seq_operations raw_seq_ops = { ...@@ -902,24 +902,8 @@ static const struct seq_operations raw_seq_ops = {
static int raw_seq_open(struct inode *inode, struct file *file) static int raw_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &raw_seq_ops,
int rc = -ENOMEM; sizeof(struct raw_iter_state));
struct raw_iter_state *s;
s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &raw_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations raw_seq_fops = { static const struct file_operations raw_seq_fops = {
......
...@@ -375,23 +375,8 @@ static const struct seq_operations rt_cache_seq_ops = { ...@@ -375,23 +375,8 @@ static const struct seq_operations rt_cache_seq_ops = {
static int rt_cache_seq_open(struct inode *inode, struct file *file) static int rt_cache_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &rt_cache_seq_ops,
int rc = -ENOMEM; sizeof(struct rt_cache_iter_state));
struct rt_cache_iter_state *s;
s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &rt_cache_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations rt_cache_seq_fops = { static const struct file_operations rt_cache_seq_fops = {
......
...@@ -2806,24 +2806,8 @@ static const struct seq_operations if6_seq_ops = { ...@@ -2806,24 +2806,8 @@ static const struct seq_operations if6_seq_ops = {
static int if6_seq_open(struct inode *inode, struct file *file) static int if6_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &if6_seq_ops,
int rc = -ENOMEM; sizeof(struct if6_iter_state));
struct if6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &if6_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations if6_fops = { static const struct file_operations if6_fops = {
......
...@@ -549,24 +549,8 @@ static const struct seq_operations ac6_seq_ops = { ...@@ -549,24 +549,8 @@ static const struct seq_operations ac6_seq_ops = {
static int ac6_seq_open(struct inode *inode, struct file *file) static int ac6_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &ac6_seq_ops,
int rc = -ENOMEM; sizeof(struct ac6_iter_state));
struct ac6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &ac6_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations ac6_seq_fops = { static const struct file_operations ac6_seq_fops = {
......
...@@ -658,24 +658,8 @@ static const struct seq_operations ip6fl_seq_ops = { ...@@ -658,24 +658,8 @@ static const struct seq_operations ip6fl_seq_ops = {
static int ip6fl_seq_open(struct inode *inode, struct file *file) static int ip6fl_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &ip6fl_seq_ops,
int rc = -ENOMEM; sizeof(struct ip6fl_iter_state));
struct ip6fl_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &ip6fl_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations ip6fl_seq_fops = { static const struct file_operations ip6fl_seq_fops = {
......
...@@ -2426,24 +2426,8 @@ static const struct seq_operations igmp6_mc_seq_ops = { ...@@ -2426,24 +2426,8 @@ static const struct seq_operations igmp6_mc_seq_ops = {
static int igmp6_mc_seq_open(struct inode *inode, struct file *file) static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &igmp6_mc_seq_ops,
int rc = -ENOMEM; sizeof(struct igmp6_mc_iter_state));
struct igmp6_mc_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &igmp6_mc_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations igmp6_mc_seq_fops = { static const struct file_operations igmp6_mc_seq_fops = {
...@@ -2600,24 +2584,8 @@ static const struct seq_operations igmp6_mcf_seq_ops = { ...@@ -2600,24 +2584,8 @@ static const struct seq_operations igmp6_mcf_seq_ops = {
static int igmp6_mcf_seq_open(struct inode *inode, struct file *file) static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &igmp6_mcf_seq_ops,
int rc = -ENOMEM; sizeof(struct igmp6_mcf_iter_state));
struct igmp6_mcf_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &igmp6_mcf_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations igmp6_mcf_seq_fops = { static const struct file_operations igmp6_mcf_seq_fops = {
......
...@@ -1289,21 +1289,8 @@ static const struct seq_operations raw6_seq_ops = { ...@@ -1289,21 +1289,8 @@ static const struct seq_operations raw6_seq_ops = {
static int raw6_seq_open(struct inode *inode, struct file *file) static int raw6_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &raw6_seq_ops,
int rc = -ENOMEM; sizeof(struct raw6_iter_state));
struct raw6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
rc = seq_open(file, &raw6_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = s;
out:
return rc;
out_kfree:
kfree(s);
goto out;
} }
static const struct file_operations raw6_seq_fops = { static const struct file_operations raw6_seq_fops = {
......
...@@ -1845,27 +1845,18 @@ static const struct seq_operations netlink_seq_ops = { ...@@ -1845,27 +1845,18 @@ static const struct seq_operations netlink_seq_ops = {
static int netlink_seq_open(struct inode *inode, struct file *file) static int netlink_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq;
struct nl_seq_iter *iter; struct nl_seq_iter *iter;
int err;
iter = kzalloc(sizeof(*iter), GFP_KERNEL); iter = __seq_open_private(file, &netlink_seq_ops, sizeof(*iter));
if (!iter) if (!iter)
return -ENOMEM; return -ENOMEM;
err = seq_open(file, &netlink_seq_ops);
if (err) {
kfree(iter);
return err;
}
seq = file->private_data;
seq->private = iter;
iter->net = get_proc_net(inode); iter->net = get_proc_net(inode);
if (!iter->net) { if (!iter->net) {
seq_release_private(inode, file); seq_release_private(inode, file);
return -ENXIO; return -ENXIO;
} }
return 0; return 0;
} }
......
...@@ -2086,25 +2086,7 @@ static const struct seq_operations unix_seq_ops = { ...@@ -2086,25 +2086,7 @@ static const struct seq_operations unix_seq_ops = {
static int unix_seq_open(struct inode *inode, struct file *file) static int unix_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; return seq_open_private(file, &unix_seq_ops, sizeof(int));
int rc = -ENOMEM;
int *iter = kmalloc(sizeof(int), GFP_KERNEL);
if (!iter)
goto out;
rc = seq_open(file, &unix_seq_ops);
if (rc)
goto out_kfree;
seq = file->private_data;
seq->private = iter;
*iter = 0;
out:
return rc;
out_kfree:
kfree(iter);
goto out;
} }
static const struct file_operations unix_seq_fops = { static const struct file_operations unix_seq_fops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment