aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@ZenIV.linux.org.uk>2018-03-16 19:32:51 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-17 20:11:22 -0400
commitd47d08c8ca052df3d9fde7cfff518660335b16e7 (patch)
treed71c38e8e93706a871edfbfa0eab429fe1622156
parent90e2c7a1248d422cb21665ff6da52442c245963d (diff)
sctp: use proc_remove_subtree()
use proc_remove_subtree() for subtree removal, both on setup failure halfway through and on teardown. No need to make simple things complex... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/sctp/sctp.h11
-rw-r--r--net/sctp/objcnt.c8
-rw-r--r--net/sctp/proc.c90
-rw-r--r--net/sctp/protocol.c59
4 files changed, 28 insertions, 140 deletions
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index f7ae6b0a21d0..72c5b8fc3232 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -180,14 +180,7 @@ struct sctp_transport *sctp_epaddr_lookup_transport(
180/* 180/*
181 * sctp/proc.c 181 * sctp/proc.c
182 */ 182 */
183int sctp_snmp_proc_init(struct net *net); 183int __net_init sctp_proc_init(struct net *net);
184void sctp_snmp_proc_exit(struct net *net);
185int sctp_eps_proc_init(struct net *net);
186void sctp_eps_proc_exit(struct net *net);
187int sctp_assocs_proc_init(struct net *net);
188void sctp_assocs_proc_exit(struct net *net);
189int sctp_remaddr_proc_init(struct net *net);
190void sctp_remaddr_proc_exit(struct net *net);
191 184
192/* 185/*
193 * sctp/offload.c 186 * sctp/offload.c
@@ -318,7 +311,6 @@ atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0)
318{.label= #name, .counter= &sctp_dbg_objcnt_## name} 311{.label= #name, .counter= &sctp_dbg_objcnt_## name}
319 312
320void sctp_dbg_objcnt_init(struct net *); 313void sctp_dbg_objcnt_init(struct net *);
321void sctp_dbg_objcnt_exit(struct net *);
322 314
323#else 315#else
324 316
@@ -326,7 +318,6 @@ void sctp_dbg_objcnt_exit(struct net *);
326#define SCTP_DBG_OBJCNT_DEC(name) 318#define SCTP_DBG_OBJCNT_DEC(name)
327 319
328static inline void sctp_dbg_objcnt_init(struct net *net) { return; } 320static inline void sctp_dbg_objcnt_init(struct net *net) { return; }
329static inline void sctp_dbg_objcnt_exit(struct net *net) { return; }
330 321
331#endif /* CONFIG_SCTP_DBG_OBJCOUNT */ 322#endif /* CONFIG_SCTP_DBG_OBJCOUNT */
332 323
diff --git a/net/sctp/objcnt.c b/net/sctp/objcnt.c
index aeea6da81441..fd2684ad94c8 100644
--- a/net/sctp/objcnt.c
+++ b/net/sctp/objcnt.c
@@ -130,11 +130,3 @@ void sctp_dbg_objcnt_init(struct net *net)
130 if (!ent) 130 if (!ent)
131 pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n"); 131 pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n");
132} 132}
133
134/* Cleanup the objcount entry in the proc filesystem. */
135void sctp_dbg_objcnt_exit(struct net *net)
136{
137 remove_proc_entry("sctp_dbg_objcnt", net->sctp.proc_net_sctp);
138}
139
140
diff --git a/net/sctp/proc.c b/net/sctp/proc.c
index 537545ebcb0e..17d0155d9de3 100644
--- a/net/sctp/proc.c
+++ b/net/sctp/proc.c
@@ -101,25 +101,6 @@ static const struct file_operations sctp_snmp_seq_fops = {
101 .release = single_release_net, 101 .release = single_release_net,
102}; 102};
103 103
104/* Set up the proc fs entry for 'snmp' object. */
105int __net_init sctp_snmp_proc_init(struct net *net)
106{
107 struct proc_dir_entry *p;
108
109 p = proc_create("snmp", S_IRUGO, net->sctp.proc_net_sctp,
110 &sctp_snmp_seq_fops);
111 if (!p)
112 return -ENOMEM;
113
114 return 0;
115}
116
117/* Cleanup the proc fs entry for 'snmp' object. */
118void sctp_snmp_proc_exit(struct net *net)
119{
120 remove_proc_entry("snmp", net->sctp.proc_net_sctp);
121}
122
123/* Dump local addresses of an association/endpoint. */ 104/* Dump local addresses of an association/endpoint. */
124static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb) 105static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
125{ 106{
@@ -259,25 +240,6 @@ static const struct file_operations sctp_eps_seq_fops = {
259 .release = seq_release_net, 240 .release = seq_release_net,
260}; 241};
261 242
262/* Set up the proc fs entry for 'eps' object. */
263int __net_init sctp_eps_proc_init(struct net *net)
264{
265 struct proc_dir_entry *p;
266
267 p = proc_create("eps", S_IRUGO, net->sctp.proc_net_sctp,
268 &sctp_eps_seq_fops);
269 if (!p)
270 return -ENOMEM;
271
272 return 0;
273}
274
275/* Cleanup the proc fs entry for 'eps' object. */
276void sctp_eps_proc_exit(struct net *net)
277{
278 remove_proc_entry("eps", net->sctp.proc_net_sctp);
279}
280
281struct sctp_ht_iter { 243struct sctp_ht_iter {
282 struct seq_net_private p; 244 struct seq_net_private p;
283 struct rhashtable_iter hti; 245 struct rhashtable_iter hti;
@@ -390,25 +352,6 @@ static const struct file_operations sctp_assocs_seq_fops = {
390 .release = seq_release_net, 352 .release = seq_release_net,
391}; 353};
392 354
393/* Set up the proc fs entry for 'assocs' object. */
394int __net_init sctp_assocs_proc_init(struct net *net)
395{
396 struct proc_dir_entry *p;
397
398 p = proc_create("assocs", S_IRUGO, net->sctp.proc_net_sctp,
399 &sctp_assocs_seq_fops);
400 if (!p)
401 return -ENOMEM;
402
403 return 0;
404}
405
406/* Cleanup the proc fs entry for 'assocs' object. */
407void sctp_assocs_proc_exit(struct net *net)
408{
409 remove_proc_entry("assocs", net->sctp.proc_net_sctp);
410}
411
412static int sctp_remaddr_seq_show(struct seq_file *seq, void *v) 355static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
413{ 356{
414 struct sctp_association *assoc; 357 struct sctp_association *assoc;
@@ -488,12 +431,6 @@ static const struct seq_operations sctp_remaddr_ops = {
488 .show = sctp_remaddr_seq_show, 431 .show = sctp_remaddr_seq_show,
489}; 432};
490 433
491/* Cleanup the proc fs entry for 'remaddr' object. */
492void sctp_remaddr_proc_exit(struct net *net)
493{
494 remove_proc_entry("remaddr", net->sctp.proc_net_sctp);
495}
496
497static int sctp_remaddr_seq_open(struct inode *inode, struct file *file) 434static int sctp_remaddr_seq_open(struct inode *inode, struct file *file)
498{ 435{
499 return seq_open_net(inode, file, &sctp_remaddr_ops, 436 return seq_open_net(inode, file, &sctp_remaddr_ops,
@@ -507,13 +444,28 @@ static const struct file_operations sctp_remaddr_seq_fops = {
507 .release = seq_release_net, 444 .release = seq_release_net,
508}; 445};
509 446
510int __net_init sctp_remaddr_proc_init(struct net *net) 447/* Set up the proc fs entry for the SCTP protocol. */
448int __net_init sctp_proc_init(struct net *net)
511{ 449{
512 struct proc_dir_entry *p; 450 net->sctp.proc_net_sctp = proc_net_mkdir(net, "sctp", net->proc_net);
513 451 if (!net->sctp.proc_net_sctp)
514 p = proc_create("remaddr", S_IRUGO, net->sctp.proc_net_sctp,
515 &sctp_remaddr_seq_fops);
516 if (!p)
517 return -ENOMEM; 452 return -ENOMEM;
453 if (!proc_create("snmp", S_IRUGO, net->sctp.proc_net_sctp,
454 &sctp_snmp_seq_fops))
455 goto cleanup;
456 if (!proc_create("eps", S_IRUGO, net->sctp.proc_net_sctp,
457 &sctp_eps_seq_fops))
458 goto cleanup;
459 if (!proc_create("assocs", S_IRUGO, net->sctp.proc_net_sctp,
460 &sctp_assocs_seq_fops))
461 goto cleanup;
462 if (!proc_create("remaddr", S_IRUGO, net->sctp.proc_net_sctp,
463 &sctp_remaddr_seq_fops))
464 goto cleanup;
518 return 0; 465 return 0;
466
467cleanup:
468 remove_proc_subtree("sctp", net->proc_net);
469 net->sctp.proc_net_sctp = NULL;
470 return -ENOMEM;
519} 471}
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 606361ee9e4a..493b817f6a2a 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -80,56 +80,6 @@ long sysctl_sctp_mem[3];
80int sysctl_sctp_rmem[3]; 80int sysctl_sctp_rmem[3];
81int sysctl_sctp_wmem[3]; 81int sysctl_sctp_wmem[3];
82 82
83/* Set up the proc fs entry for the SCTP protocol. */
84static int __net_init sctp_proc_init(struct net *net)
85{
86#ifdef CONFIG_PROC_FS
87 net->sctp.proc_net_sctp = proc_net_mkdir(net, "sctp", net->proc_net);
88 if (!net->sctp.proc_net_sctp)
89 goto out_proc_net_sctp;
90 if (sctp_snmp_proc_init(net))
91 goto out_snmp_proc_init;
92 if (sctp_eps_proc_init(net))
93 goto out_eps_proc_init;
94 if (sctp_assocs_proc_init(net))
95 goto out_assocs_proc_init;
96 if (sctp_remaddr_proc_init(net))
97 goto out_remaddr_proc_init;
98
99 return 0;
100
101out_remaddr_proc_init:
102 sctp_assocs_proc_exit(net);
103out_assocs_proc_init:
104 sctp_eps_proc_exit(net);
105out_eps_proc_init:
106 sctp_snmp_proc_exit(net);
107out_snmp_proc_init:
108 remove_proc_entry("sctp", net->proc_net);
109 net->sctp.proc_net_sctp = NULL;
110out_proc_net_sctp:
111 return -ENOMEM;
112#endif /* CONFIG_PROC_FS */
113 return 0;
114}
115
116/* Clean up the proc fs entry for the SCTP protocol.
117 * Note: Do not make this __exit as it is used in the init error
118 * path.
119 */
120static void sctp_proc_exit(struct net *net)
121{
122#ifdef CONFIG_PROC_FS
123 sctp_snmp_proc_exit(net);
124 sctp_eps_proc_exit(net);
125 sctp_assocs_proc_exit(net);
126 sctp_remaddr_proc_exit(net);
127
128 remove_proc_entry("sctp", net->proc_net);
129 net->sctp.proc_net_sctp = NULL;
130#endif
131}
132
133/* Private helper to extract ipv4 address and stash them in 83/* Private helper to extract ipv4 address and stash them in
134 * the protocol structure. 84 * the protocol structure.
135 */ 85 */
@@ -1285,10 +1235,12 @@ static int __net_init sctp_defaults_init(struct net *net)
1285 if (status) 1235 if (status)
1286 goto err_init_mibs; 1236 goto err_init_mibs;
1287 1237
1238#ifdef CONFIG_PROC_FS
1288 /* Initialize proc fs directory. */ 1239 /* Initialize proc fs directory. */
1289 status = sctp_proc_init(net); 1240 status = sctp_proc_init(net);
1290 if (status) 1241 if (status)
1291 goto err_init_proc; 1242 goto err_init_proc;
1243#endif
1292 1244
1293 sctp_dbg_objcnt_init(net); 1245 sctp_dbg_objcnt_init(net);
1294 1246
@@ -1320,9 +1272,10 @@ static void __net_exit sctp_defaults_exit(struct net *net)
1320 sctp_free_addr_wq(net); 1272 sctp_free_addr_wq(net);
1321 sctp_free_local_addr_list(net); 1273 sctp_free_local_addr_list(net);
1322 1274
1323 sctp_dbg_objcnt_exit(net); 1275#ifdef CONFIG_PROC_FS
1324 1276 remove_proc_subtree("sctp", net->proc_net);
1325 sctp_proc_exit(net); 1277 net->sctp.proc_net_sctp = NULL;
1278#endif
1326 cleanup_sctp_mibs(net); 1279 cleanup_sctp_mibs(net);
1327 sctp_sysctl_net_unregister(net); 1280 sctp_sysctl_net_unregister(net);
1328} 1281}