drop mbcache-fix-potential-double-count-when-removing-entry
[ext4-patch-queue.git] / make-sure-c_entry_count-does-not-get-decremented-past-zero
blob85263cf2c76391fa5a89611302d3689e960860d4
1 mbcache: make sure c_entry_count is not decremented past zero
3 From: Jiang Biao <jiang.biao2@zte.com.cn>
5 Signed-off-by: Jiang Biao <jiang.biao2@zte.com.cn>
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 CC: Eric Biggers <ebiggers@google.com>
8 CC: Andrew Morton <akpm@linux-foundation.org>
9 CC: Jan Kara <jack@suse.cz>
10 ---
11  fs/mbcache.c | 4 +++-
12  1 file changed, 3 insertions(+), 1 deletion(-)
14 diff --git a/fs/mbcache.c b/fs/mbcache.c
15 index 0851af5c1c3d..f2f15b747bed 100644
16 --- a/fs/mbcache.c
17 +++ b/fs/mbcache.c
18 @@ -239,7 +239,9 @@ void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value)
19                         spin_lock(&cache->c_list_lock);
20                         if (!list_empty(&entry->e_list)) {
21                                 list_del_init(&entry->e_list);
22 -                               cache->c_entry_count--;
23 +                               if (!WARN_ONCE(cache->c_entry_count == 0,
24 +               "mbcache: attempt to decrement c_entry_count past zero"))
25 +                                       cache->c_entry_count--;
26                                 atomic_dec(&entry->e_refcnt);
27                         }
28                         spin_unlock(&cache->c_list_lock);