summaryrefslogtreecommitdiffstats
path: root/fs/mbcache.c
diff options
context:
space:
mode:
authorChao Yu <yuchao0@huawei.com>2016-08-31 11:44:36 -0400
committerTheodore Ts'o <tytso@mit.edu>2016-08-31 11:44:36 -0400
commit8913f343cdb568222c95afe3cad78aee1a4df56b (patch)
tree8a66c63713f0a8c284e1029fd2504164c0050d59 /fs/mbcache.c
parent14fbd4aa613bd5110556c281799ce36dc6f3ba97 (diff)
downloadlinux-8913f343cdb568222c95afe3cad78aee1a4df56b.tar.bz2
mbcache: fix to detect failure of register_shrinker
register_shrinker in mb_cache_create may fail due to no memory. This patch fixes to do the check of return value of register_shrinker and handle the error case, otherwise mb_cache_create may return with no error, but losing the inner shrinker. Signed-off-by: Chao Yu <yuchao0@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/mbcache.c')
-rw-r--r--fs/mbcache.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/mbcache.c b/fs/mbcache.c
index eccda3a02de6..c5bd19ffa326 100644
--- a/fs/mbcache.c
+++ b/fs/mbcache.c
@@ -366,7 +366,11 @@ struct mb_cache *mb_cache_create(int bucket_bits)
cache->c_shrink.count_objects = mb_cache_count;
cache->c_shrink.scan_objects = mb_cache_scan;
cache->c_shrink.seeks = DEFAULT_SEEKS;
- register_shrinker(&cache->c_shrink);
+ if (register_shrinker(&cache->c_shrink)) {
+ kfree(cache->c_hash);
+ kfree(cache);
+ goto err_out;
+ }
INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker);