Skip to content

Commit d47d08c

Browse files
Al Virodavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 90e2c7a commit d47d08c

File tree

4 files changed

+28
-140
lines changed

4 files changed

+28
-140
lines changed

include/net/sctp/sctp.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,7 @@ struct sctp_transport *sctp_epaddr_lookup_transport(
180180
/*
181181
* sctp/proc.c
182182
*/
183-
int sctp_snmp_proc_init(struct net *net);
184-
void sctp_snmp_proc_exit(struct net *net);
185-
int sctp_eps_proc_init(struct net *net);
186-
void sctp_eps_proc_exit(struct net *net);
187-
int sctp_assocs_proc_init(struct net *net);
188-
void sctp_assocs_proc_exit(struct net *net);
189-
int sctp_remaddr_proc_init(struct net *net);
190-
void sctp_remaddr_proc_exit(struct net *net);
183+
int __net_init sctp_proc_init(struct net *net);
191184

192185
/*
193186
* sctp/offload.c
@@ -318,15 +311,13 @@ atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0)
318311
{.label= #name, .counter= &sctp_dbg_objcnt_## name}
319312

320313
void sctp_dbg_objcnt_init(struct net *);
321-
void sctp_dbg_objcnt_exit(struct net *);
322314

323315
#else
324316

325317
#define SCTP_DBG_OBJCNT_INC(name)
326318
#define SCTP_DBG_OBJCNT_DEC(name)
327319

328320
static inline void sctp_dbg_objcnt_init(struct net *net) { return; }
329-
static inline void sctp_dbg_objcnt_exit(struct net *net) { return; }
330321

331322
#endif /* CONFIG_SCTP_DBG_OBJCOUNT */
332323

net/sctp/objcnt.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,3 @@ void sctp_dbg_objcnt_init(struct net *net)
130130
if (!ent)
131131
pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n");
132132
}
133-
134-
/* Cleanup the objcount entry in the proc filesystem. */
135-
void sctp_dbg_objcnt_exit(struct net *net)
136-
{
137-
remove_proc_entry("sctp_dbg_objcnt", net->sctp.proc_net_sctp);
138-
}
139-
140-

net/sctp/proc.c

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,6 @@ static const struct file_operations sctp_snmp_seq_fops = {
101101
.release = single_release_net,
102102
};
103103

104-
/* Set up the proc fs entry for 'snmp' object. */
105-
int __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. */
118-
void sctp_snmp_proc_exit(struct net *net)
119-
{
120-
remove_proc_entry("snmp", net->sctp.proc_net_sctp);
121-
}
122-
123104
/* Dump local addresses of an association/endpoint. */
124105
static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
125106
{
@@ -259,25 +240,6 @@ static const struct file_operations sctp_eps_seq_fops = {
259240
.release = seq_release_net,
260241
};
261242

262-
/* Set up the proc fs entry for 'eps' object. */
263-
int __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. */
276-
void sctp_eps_proc_exit(struct net *net)
277-
{
278-
remove_proc_entry("eps", net->sctp.proc_net_sctp);
279-
}
280-
281243
struct sctp_ht_iter {
282244
struct seq_net_private p;
283245
struct rhashtable_iter hti;
@@ -390,25 +352,6 @@ static const struct file_operations sctp_assocs_seq_fops = {
390352
.release = seq_release_net,
391353
};
392354

393-
/* Set up the proc fs entry for 'assocs' object. */
394-
int __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. */
407-
void sctp_assocs_proc_exit(struct net *net)
408-
{
409-
remove_proc_entry("assocs", net->sctp.proc_net_sctp);
410-
}
411-
412355
static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
413356
{
414357
struct sctp_association *assoc;
@@ -488,12 +431,6 @@ static const struct seq_operations sctp_remaddr_ops = {
488431
.show = sctp_remaddr_seq_show,
489432
};
490433

491-
/* Cleanup the proc fs entry for 'remaddr' object. */
492-
void sctp_remaddr_proc_exit(struct net *net)
493-
{
494-
remove_proc_entry("remaddr", net->sctp.proc_net_sctp);
495-
}
496-
497434
static int sctp_remaddr_seq_open(struct inode *inode, struct file *file)
498435
{
499436
return seq_open_net(inode, file, &sctp_remaddr_ops,
@@ -507,13 +444,28 @@ static const struct file_operations sctp_remaddr_seq_fops = {
507444
.release = seq_release_net,
508445
};
509446

510-
int __net_init sctp_remaddr_proc_init(struct net *net)
447+
/* Set up the proc fs entry for the SCTP protocol. */
448+
int __net_init sctp_proc_init(struct net *net)
511449
{
512-
struct proc_dir_entry *p;
513-
514-
p = proc_create("remaddr", S_IRUGO, net->sctp.proc_net_sctp,
515-
&sctp_remaddr_seq_fops);
516-
if (!p)
450+
net->sctp.proc_net_sctp = proc_net_mkdir(net, "sctp", net->proc_net);
451+
if (!net->sctp.proc_net_sctp)
517452
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;
518465
return 0;
466+
467+
cleanup:
468+
remove_proc_subtree("sctp", net->proc_net);
469+
net->sctp.proc_net_sctp = NULL;
470+
return -ENOMEM;
519471
}

net/sctp/protocol.c

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -80,56 +80,6 @@ long sysctl_sctp_mem[3];
8080
int sysctl_sctp_rmem[3];
8181
int sysctl_sctp_wmem[3];
8282

83-
/* Set up the proc fs entry for the SCTP protocol. */
84-
static 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-
101-
out_remaddr_proc_init:
102-
sctp_assocs_proc_exit(net);
103-
out_assocs_proc_init:
104-
sctp_eps_proc_exit(net);
105-
out_eps_proc_init:
106-
sctp_snmp_proc_exit(net);
107-
out_snmp_proc_init:
108-
remove_proc_entry("sctp", net->proc_net);
109-
net->sctp.proc_net_sctp = NULL;
110-
out_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-
*/
120-
static 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-
13383
/* Private helper to extract ipv4 address and stash them in
13484
* the protocol structure.
13585
*/
@@ -1285,10 +1235,12 @@ static int __net_init sctp_defaults_init(struct net *net)
12851235
if (status)
12861236
goto err_init_mibs;
12871237

1238+
#ifdef CONFIG_PROC_FS
12881239
/* Initialize proc fs directory. */
12891240
status = sctp_proc_init(net);
12901241
if (status)
12911242
goto err_init_proc;
1243+
#endif
12921244

12931245
sctp_dbg_objcnt_init(net);
12941246

@@ -1320,9 +1272,10 @@ static void __net_exit sctp_defaults_exit(struct net *net)
13201272
sctp_free_addr_wq(net);
13211273
sctp_free_local_addr_list(net);
13221274

1323-
sctp_dbg_objcnt_exit(net);
1324-
1325-
sctp_proc_exit(net);
1275+
#ifdef CONFIG_PROC_FS
1276+
remove_proc_subtree("sctp", net->proc_net);
1277+
net->sctp.proc_net_sctp = NULL;
1278+
#endif
13261279
cleanup_sctp_mibs(net);
13271280
sctp_sysctl_net_unregister(net);
13281281
}

0 commit comments

Comments
 (0)