Skip to content

Commit 9cdd83e

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc: switch struct proc_dir_entry::count to refcount
->count is honest reference count unlike ->in_use. Link: http://lkml.kernel.org/r/20180313174550.GA4332@avx2 Signed-off-by: Alexey Dobriyan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b77d70d commit 9cdd83e

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

fs/proc/generic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
402402
ent->mode = mode;
403403
ent->nlink = nlink;
404404
ent->subdir = RB_ROOT_CACHED;
405-
atomic_set(&ent->count, 1);
405+
refcount_set(&ent->refcnt, 1);
406406
spin_lock_init(&ent->pde_unload_lock);
407407
INIT_LIST_HEAD(&ent->pde_openers);
408408
proc_set_user(ent, (*parent)->uid, (*parent)->gid);
@@ -553,7 +553,7 @@ EXPORT_SYMBOL(proc_set_user);
553553

554554
void pde_put(struct proc_dir_entry *pde)
555555
{
556-
if (atomic_dec_and_test(&pde->count)) {
556+
if (refcount_dec_and_test(&pde->refcnt)) {
557557
proc_free_inum(pde->low_ino);
558558
pde_free(pde);
559559
}

fs/proc/internal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/proc_fs.h>
1313
#include <linux/proc_ns.h>
14+
#include <linux/refcount.h>
1415
#include <linux/spinlock.h>
1516
#include <linux/atomic.h>
1617
#include <linux/binfmts.h>
@@ -36,7 +37,7 @@ struct proc_dir_entry {
3637
* negative -> it's going away RSN
3738
*/
3839
atomic_t in_use;
39-
atomic_t count; /* use count */
40+
refcount_t refcnt;
4041
struct list_head pde_openers; /* who did ->open, but not ->release */
4142
/* protects ->pde_openers and all struct pde_opener instances */
4243
spinlock_t pde_unload_lock;
@@ -168,7 +169,7 @@ int proc_readdir_de(struct file *, struct dir_context *, struct proc_dir_entry *
168169

169170
static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
170171
{
171-
atomic_inc(&pde->count);
172+
refcount_inc(&pde->refcnt);
172173
return pde;
173174
}
174175
extern void pde_put(struct proc_dir_entry *);

fs/proc/root.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ struct proc_dir_entry proc_root = {
199199
.namelen = 5,
200200
.mode = S_IFDIR | S_IRUGO | S_IXUGO,
201201
.nlink = 2,
202-
.count = ATOMIC_INIT(1),
202+
.refcnt = REFCOUNT_INIT(1),
203203
.proc_iops = &proc_root_inode_operations,
204204
.proc_fops = &proc_root_operations,
205205
.parent = &proc_root,

0 commit comments

Comments
 (0)