Skip to content

Commit

Permalink
mbcache: fix to detect failure of register_shrinker
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chao Yu authored and Theodore Ts'o committed Aug 31, 2016
1 parent 14fbd4a commit 8913f34
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs/mbcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 8913f34

Please sign in to comment.