1 mbcache: fix to detect failure of register_shrinker
3 From: Chao Yu <yuchao0@huawei.com>
5 register_shrinker in mb_cache_create may fail due to no memory. This
6 patch fixes to do the check of return value of register_shrinker and
7 handle the error case, otherwise mb_cache_create may return with no
8 error, but losing the inner shrinker.
10 Signed-off-by: Chao Yu <yuchao0@huawei.com>
11 Reviewed-by: Jan Kara <jack@suse.cz>
12 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 fs/mbcache.c | 6 +++++-
15 1 file changed, 5 insertions(+), 1 deletion(-)
17 diff --git a/fs/mbcache.c b/fs/mbcache.c
18 index eccda3a..c5bd19f 100644
21 @@ -366,7 +366,11 @@ struct mb_cache *mb_cache_create(int bucket_bits)
22 cache->c_shrink.count_objects = mb_cache_count;
23 cache->c_shrink.scan_objects = mb_cache_scan;
24 cache->c_shrink.seeks = DEFAULT_SEEKS;
25 - register_shrinker(&cache->c_shrink);
26 + if (register_shrinker(&cache->c_shrink)) {
27 + kfree(cache->c_hash);
32 INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker);