[NET]: Make core networking code use seq_open_private
authorPavel Emelyanov <xemul@openvz.org>
Wed, 10 Oct 2007 09:29:29 +0000 (02:29 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Wed, 10 Oct 2007 23:55:33 +0000 (16:55 -0700)
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: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
15 files changed:
net/ipv4/arp.c
net/ipv4/fib_hash.c
net/ipv4/fib_trie.c
net/ipv4/igmp.c
net/ipv4/ipmr.c
net/ipv4/ipvs/ip_vs_ctl.c
net/ipv4/raw.c
net/ipv4/route.c
net/ipv6/addrconf.c
net/ipv6/anycast.c
net/ipv6/ip6_flowlabel.c
net/ipv6/mcast.c
net/ipv6/raw.c
net/netlink/af_netlink.c
net/unix/af_unix.c

index d8248198bcd721611336f38276ce84310ea53384..36d6798947b59026eb400c6b06882099fddd8ba0 100644 (file)
@@ -1378,24 +1378,8 @@ static const struct seq_operations arp_seq_ops = {
 
 static int arp_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &arp_seq_ops,
+                       sizeof(struct neigh_seq_state));
 }
 
 static const struct file_operations arp_seq_fops = {
index 9fafbeea8fe64f4b4f5f219b7f814d8b13f82a2c..527a6e0af5b60eb48b9e15459e8877db10c29db8 100644 (file)
@@ -1039,24 +1039,8 @@ static const struct seq_operations fib_seq_ops = {
 
 static int fib_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &fib_seq_ops,
+                       sizeof(struct fib_iter_state));
 }
 
 static const struct file_operations fib_seq_fops = {
index be34bd556d58ea5a041dc10de3d98201ead4eb03..81a8285d6d6a4251c7cd166635f7058046078bf6 100644 (file)
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &fib_trie_seq_ops,
+                       sizeof(struct fib_trie_iter));
 }
 
 static const struct file_operations fib_trie_fops = {
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &fib_route_seq_ops,
+                       sizeof(struct fib_trie_iter));
 }
 
 static const struct file_operations fib_route_fops = {
index 2b6e59c4c0d058acbc791111f11ba2d48d98476f..7dbc282d4f9f3eb86a363f19f0fa19f29f1ad97b 100644 (file)
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &igmp_mc_seq_ops,
+                       sizeof(struct igmp_mc_iter_state));
 }
 
 static const struct file_operations igmp_mc_seq_fops = {
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &igmp_mcf_seq_ops,
+                       sizeof(struct igmp_mcf_iter_state));
 }
 
 static const struct file_operations igmp_mcf_seq_fops = {
index b8b4b497fb57309a3321960dd5d913542ed3e3cd..37bb497d92af2af2d714ed4d4694d25a4b9c5471 100644 (file)
@@ -1714,26 +1714,8 @@ static const struct seq_operations ipmr_vif_seq_ops = {
 
 static int ipmr_vif_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
-
+       return seq_open_private(file, &ipmr_vif_seq_ops,
+                       sizeof(struct ipmr_vif_iter));
 }
 
 static const struct file_operations ipmr_vif_fops = {
@@ -1877,25 +1859,8 @@ static const struct seq_operations ipmr_mfc_seq_ops = {
 
 static int ipmr_mfc_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
-
+       return seq_open_private(file, &ipmr_mfc_seq_ops,
+                       sizeof(struct ipmr_mfc_iter));
 }
 
 static const struct file_operations ipmr_mfc_fops = {
index 61d023d58b5d8c86cc853ac951be87e97716df34..7345fc252a2315943b77c084a05ecaa45668d3e5 100644 (file)
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &ip_vs_info_seq_ops,
+                       sizeof(struct ip_vs_iter));
 }
 
 static const struct file_operations ip_vs_info_fops = {
index 07070c7067f3b78fe88a9f961266461d7a6920bb..3916faca3afef64fcbc8d583715b384f364c56d7 100644 (file)
@@ -902,24 +902,8 @@ static const struct seq_operations raw_seq_ops = {
 
 static int raw_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &raw_seq_ops,
+                       sizeof(struct raw_iter_state));
 }
 
 static const struct file_operations raw_seq_fops = {
index 307e1f1107ca846230742289121e5d73709b10b9..21b12de9e6536663d5da2b60bd1d94b1d984acdd 100644 (file)
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &rt_cache_seq_ops,
+                       sizeof(struct rt_cache_iter_state));
 }
 
 static const struct file_operations rt_cache_seq_fops = {
index 6d5c3c299148dc940bf002e4381b7d8338dcd07f..8b2d760ddf26fb29260ce70d3dbc0d2e02373636 100644 (file)
@@ -2806,24 +2806,8 @@ static const struct seq_operations if6_seq_ops = {
 
 static int if6_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &if6_seq_ops,
+                       sizeof(struct if6_iter_state));
 }
 
 static const struct file_operations if6_fops = {
index 5810852c558a7d48d44a4a74b04f0779a466e3a1..f915c4df9820085fb5a5ff5798c152f89e4f7f4d 100644 (file)
@@ -549,24 +549,8 @@ static const struct seq_operations ac6_seq_ops = {
 
 static int ac6_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &ac6_seq_ops,
+                       sizeof(struct ac6_iter_state));
 }
 
 static const struct file_operations ac6_seq_fops = {
index 1791399c7f103cc5985e76087b4e13f6b8a1f9a2..217d60f9fc80e89afc4e07a831ec9470c45b07e9 100644 (file)
@@ -658,24 +658,8 @@ static const struct seq_operations ip6fl_seq_ops = {
 
 static int ip6fl_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &ip6fl_seq_ops,
+                       sizeof(struct ip6fl_iter_state));
 }
 
 static const struct file_operations ip6fl_seq_fops = {
index cc8d4e2a9531268526c33f5989791696ec487288..331d728c2035920a8cbe220115ff492abd073660 100644 (file)
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &igmp6_mc_seq_ops,
+                       sizeof(struct igmp6_mc_iter_state));
 }
 
 static const struct file_operations igmp6_mc_seq_fops = {
@@ -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)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &igmp6_mcf_seq_ops,
+                       sizeof(struct igmp6_mcf_iter_state));
 }
 
 static const struct file_operations igmp6_mcf_seq_fops = {
index bdd0974e6775c6e0542369d9310a5cb10be4af2a..ca24ef19cd8f294c35d7d285751a5bb55c5d1838 100644 (file)
@@ -1289,21 +1289,8 @@ static const struct seq_operations raw6_seq_ops = {
 
 static int raw6_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       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;
+       return seq_open_private(file, &raw6_seq_ops,
+                       sizeof(struct raw6_iter_state));
 }
 
 static const struct file_operations raw6_seq_fops = {
index 3ef32825da714889079b06f796abb74aef677902..f934f54fbfd51349a98252e69f4740b6e9536bb7 100644 (file)
@@ -1845,27 +1845,18 @@ static const struct seq_operations netlink_seq_ops = {
 
 static int netlink_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
        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)
                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);
        if (!iter->net) {
                seq_release_private(inode, file);
                return -ENXIO;
        }
+
        return 0;
 }
 
index 10e73122c34c0bd23cb7a5bff61bb62c131cb4e4..2b57eaf66abc4086f7387704c1993ee399ba65c3 100644 (file)
@@ -2086,25 +2086,7 @@ static const struct seq_operations unix_seq_ops = {
 
 static int unix_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       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;
+       return seq_open_private(file, &unix_seq_ops, sizeof(int));
 }
 
 static const struct file_operations unix_seq_fops = {