aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-04-15 04:53:36 -0400
committerChristoph Hellwig <hch@lst.de>2018-05-16 01:24:30 -0400
commitce9fe43875d758c89f222d6b704bf63758f57635 (patch)
treed7275cba06b5e665fbc5b76a571abf2c4b39f8e2
parenta9170e0a923553cc12c3b00d816834316ebf226b (diff)
atm: simplify procfs code
Use remove_proc_subtree to remove the whole subtree on cleanup, and unwind the registration loop into individual calls. Switch to use proc_create_seq where applicable. Also don't bother handling proc_create* failures - the driver works perfectly fine without the proc files, and the cleanup will handle missing files gracefully. Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--net/atm/proc.c65
1 files changed, 7 insertions, 58 deletions
diff --git a/net/atm/proc.c b/net/atm/proc.c
index 55410c00c7e2..f272b0f59d82 100644
--- a/net/atm/proc.c
+++ b/net/atm/proc.c
@@ -257,18 +257,6 @@ static const struct seq_operations atm_dev_seq_ops = {
257 .show = atm_dev_seq_show, 257 .show = atm_dev_seq_show,
258}; 258};
259 259
260static int atm_dev_seq_open(struct inode *inode, struct file *file)
261{
262 return seq_open(file, &atm_dev_seq_ops);
263}
264
265static const struct file_operations devices_seq_fops = {
266 .open = atm_dev_seq_open,
267 .read = seq_read,
268 .llseek = seq_lseek,
269 .release = seq_release,
270};
271
272static int pvc_seq_show(struct seq_file *seq, void *v) 260static int pvc_seq_show(struct seq_file *seq, void *v)
273{ 261{
274 static char atm_pvc_banner[] = 262 static char atm_pvc_banner[] =
@@ -440,58 +428,19 @@ void atm_proc_dev_deregister(struct atm_dev *dev)
440 kfree(dev->proc_name); 428 kfree(dev->proc_name);
441} 429}
442 430
443static struct atm_proc_entry {
444 char *name;
445 const struct file_operations *proc_fops;
446 struct proc_dir_entry *dirent;
447} atm_proc_ents[] = {
448 { .name = "devices", .proc_fops = &devices_seq_fops },
449 { .name = "pvc", .proc_fops = &pvc_seq_fops },
450 { .name = "svc", .proc_fops = &svc_seq_fops },
451 { .name = "vc", .proc_fops = &vcc_seq_fops },
452 { .name = NULL, .proc_fops = NULL }
453};
454
455static void atm_proc_dirs_remove(void)
456{
457 static struct atm_proc_entry *e;
458
459 for (e = atm_proc_ents; e->name; e++) {
460 if (e->dirent)
461 remove_proc_entry(e->name, atm_proc_root);
462 }
463 remove_proc_entry("atm", init_net.proc_net);
464}
465
466int __init atm_proc_init(void) 431int __init atm_proc_init(void)
467{ 432{
468 static struct atm_proc_entry *e;
469 int ret;
470
471 atm_proc_root = proc_net_mkdir(&init_net, "atm", init_net.proc_net); 433 atm_proc_root = proc_net_mkdir(&init_net, "atm", init_net.proc_net);
472 if (!atm_proc_root) 434 if (!atm_proc_root)
473 goto err_out; 435 return -ENOMEM;
474 for (e = atm_proc_ents; e->name; e++) { 436 proc_create_seq("devices", 0444, atm_proc_root, &atm_dev_seq_ops);
475 struct proc_dir_entry *dirent; 437 proc_create("pvc", 0444, atm_proc_root, &pvc_seq_fops);
476 438 proc_create("svc", 0444, atm_proc_root, &svc_seq_fops);
477 dirent = proc_create(e->name, 0444, 439 proc_create("vc", 0444, atm_proc_root, &vcc_seq_fops);
478 atm_proc_root, e->proc_fops); 440 return 0;
479 if (!dirent)
480 goto err_out_remove;
481 e->dirent = dirent;
482 }
483 ret = 0;
484out:
485 return ret;
486
487err_out_remove:
488 atm_proc_dirs_remove();
489err_out:
490 ret = -ENOMEM;
491 goto out;
492} 441}
493 442
494void atm_proc_exit(void) 443void atm_proc_exit(void)
495{ 444{
496 atm_proc_dirs_remove(); 445 remove_proc_subtree("atm", init_net.proc_net);
497} 446}