At this point this is just a cleanup, since the refcount is also protected by overlayfs inode lock. This will change in a following patch. Signed-off-by: Miklos Szeredi <mszeredi@xxxxxxxxxx> --- fs/overlayfs/readdir.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c index 0ca8af060b0c..b894a97f8ef8 100644 --- a/fs/overlayfs/readdir.c +++ b/fs/overlayfs/readdir.c @@ -13,6 +13,7 @@ #include <linux/security.h> #include <linux/cred.h> #include <linux/ratelimit.h> +#include <linux/refcount.h> #include "overlayfs.h" struct ovl_cache_entry { @@ -30,7 +31,7 @@ struct ovl_cache_entry { }; struct ovl_dir_cache { - long refcount; + refcount_t refcount; u64 version; struct list_head entries; struct rb_root root; @@ -243,9 +244,7 @@ static void ovl_cache_put(struct ovl_dir_file *od, struct inode *inode) { struct ovl_dir_cache *cache = od->cache; - WARN_ON(cache->refcount <= 0); - cache->refcount--; - if (!cache->refcount) { + if (refcount_dec_and_test(&cache->refcount)) { if (ovl_dir_cache(inode) == cache) ovl_set_dir_cache(inode, NULL); @@ -405,8 +404,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) cache = ovl_dir_cache(inode); if (cache && ovl_inode_version_get(inode) == cache->version) { - WARN_ON(!cache->refcount); - cache->refcount++; + refcount_inc(&cache->refcount); return cache; } ovl_set_dir_cache(d_inode(dentry), NULL); @@ -415,7 +413,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) if (!cache) return ERR_PTR(-ENOMEM); - cache->refcount = 1; + refcount_set(&cache->refcount, 1); INIT_LIST_HEAD(&cache->entries); cache->root = RB_ROOT; -- 2.44.0