Commit 135d5655dc58a24eda64e3f6c192d7d605e10050

Authored by Alexey Dobriyan
Committed by Linus Torvalds
1 parent f065f41f48

proc: rename de_get() to pde_get() and inline it

* de_get() is trivial -- make inline, save a few bits of code, drop
  "refcount is 0" check -- it should be done in some generic refcount
  code, don't recall it's was helpful

* rename GET and PUT functions to pde_get(), pde_put() for cool prefix!

* remove obvious and incorrent comments

* in remove_proc_entry() use pde_put(), when I fixed PDE refcounting to
  be normal one, remove_proc_entry() was supposed to do "-1" and code now
  reflects that.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 23 additions and 39 deletions Side-by-side Diff

... ... @@ -429,7 +429,7 @@
429 429 unsigned int ino;
430 430  
431 431 ino = de->low_ino;
432   - de_get(de);
  432 + pde_get(de);
433 433 spin_unlock(&proc_subdir_lock);
434 434 error = -EINVAL;
435 435 inode = proc_get_inode(dir->i_sb, ino, de);
... ... @@ -445,7 +445,7 @@
445 445 return NULL;
446 446 }
447 447 if (de)
448   - de_put(de);
  448 + pde_put(de);
449 449 return ERR_PTR(error);
450 450 }
451 451  
452 452  
453 453  
... ... @@ -509,17 +509,17 @@
509 509 struct proc_dir_entry *next;
510 510  
511 511 /* filldir passes info to user space */
512   - de_get(de);
  512 + pde_get(de);
513 513 spin_unlock(&proc_subdir_lock);
514 514 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
515 515 de->low_ino, de->mode >> 12) < 0) {
516   - de_put(de);
  516 + pde_put(de);
517 517 goto out;
518 518 }
519 519 spin_lock(&proc_subdir_lock);
520 520 filp->f_pos++;
521 521 next = de->next;
522   - de_put(de);
  522 + pde_put(de);
523 523 de = next;
524 524 } while (de);
525 525 spin_unlock(&proc_subdir_lock);
... ... @@ -763,7 +763,7 @@
763 763 return NULL;
764 764 }
765 765  
766   -void free_proc_entry(struct proc_dir_entry *de)
  766 +static void free_proc_entry(struct proc_dir_entry *de)
767 767 {
768 768 unsigned int ino = de->low_ino;
769 769  
... ... @@ -777,6 +777,12 @@
777 777 kfree(de);
778 778 }
779 779  
  780 +void pde_put(struct proc_dir_entry *pde)
  781 +{
  782 + if (atomic_dec_and_test(&pde->count))
  783 + free_proc_entry(pde);
  784 +}
  785 +
780 786 /*
781 787 * Remove a /proc entry and free it if it's not currently in use.
782 788 */
... ... @@ -845,7 +851,6 @@
845 851 WARN(de->subdir, KERN_WARNING "%s: removing non-empty directory "
846 852 "'%s/%s', leaking at least '%s'\n", __func__,
847 853 de->parent->name, de->name, de->subdir->name);
848   - if (atomic_dec_and_test(&de->count))
849   - free_proc_entry(de);
  854 + pde_put(de);
850 855 }
... ... @@ -24,29 +24,6 @@
24 24  
25 25 #include "internal.h"
26 26  
27   -struct proc_dir_entry *de_get(struct proc_dir_entry *de)
28   -{
29   - atomic_inc(&de->count);
30   - return de;
31   -}
32   -
33   -/*
34   - * Decrements the use count and checks for deferred deletion.
35   - */
36   -void de_put(struct proc_dir_entry *de)
37   -{
38   - if (!atomic_read(&de->count)) {
39   - printk("de_put: entry %s already free!\n", de->name);
40   - return;
41   - }
42   -
43   - if (atomic_dec_and_test(&de->count))
44   - free_proc_entry(de);
45   -}
46   -
47   -/*
48   - * Decrement the use count of the proc_dir_entry.
49   - */
50 27 static void proc_delete_inode(struct inode *inode)
51 28 {
52 29 struct proc_dir_entry *de;
... ... @@ -59,7 +36,7 @@
59 36 /* Let go of any associated proc directory entry */
60 37 de = PROC_I(inode)->pde;
61 38 if (de)
62   - de_put(de);
  39 + pde_put(de);
63 40 if (PROC_I(inode)->sysctl)
64 41 sysctl_head_put(PROC_I(inode)->sysctl);
65 42 clear_inode(inode);
... ... @@ -480,7 +457,7 @@
480 457 }
481 458 unlock_new_inode(inode);
482 459 } else
483   - de_put(de);
  460 + pde_put(de);
484 461 return inode;
485 462 }
486 463  
... ... @@ -495,7 +472,7 @@
495 472 s->s_op = &proc_sops;
496 473 s->s_time_gran = 1;
497 474  
498   - de_get(&proc_root);
  475 + pde_get(&proc_root);
499 476 root_inode = proc_get_inode(s, PROC_ROOT_INO, &proc_root);
500 477 if (!root_inode)
501 478 goto out_no_root;
... ... @@ -509,7 +486,7 @@
509 486 out_no_root:
510 487 printk("proc_read_super: get root inode failed\n");
511 488 iput(root_inode);
512   - de_put(&proc_root);
  489 + pde_put(&proc_root);
513 490 return -ENOMEM;
514 491 }
... ... @@ -61,8 +61,6 @@
61 61 extern const struct file_operations proc_net_operations;
62 62 extern const struct inode_operations proc_net_inode_operations;
63 63  
64   -void free_proc_entry(struct proc_dir_entry *de);
65   -
66 64 void proc_init_inodecache(void);
67 65  
68 66 static inline struct pid *proc_pid(struct inode *inode)
... ... @@ -101,8 +99,12 @@
101 99 int task_statm(struct mm_struct *, int *, int *, int *, int *);
102 100 void task_mem(struct seq_file *, struct mm_struct *);
103 101  
104   -struct proc_dir_entry *de_get(struct proc_dir_entry *de);
105   -void de_put(struct proc_dir_entry *de);
  102 +static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
  103 +{
  104 + atomic_inc(&pde->count);
  105 + return pde;
  106 +}
  107 +void pde_put(struct proc_dir_entry *pde);
106 108  
107 109 extern struct vfsmount *proc_mnt;
108 110 int proc_fill_super(struct super_block *);