Skip to contentSkip to conversation

mbcache: fix to detect failure of register_shrinker

PATCH Applied Chao Yu 3 participants 6 messages May 16, 2016 – Aug 31, 2016 VFS

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 mbcache: fix to detect failure of register_shrinker

From: Chao Yu <[email protected]>

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.

---
 fs/mbcache.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/mbcache.c +5 -1
index eccda3a..c5bd19f 100644
@@ -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);
 
Signature · 1 line
2.7.2
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Chao Yu

From: Chao Yu <[email protected]>

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.

Thanks for fixing this. The patch looks good. You can add:

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
In reply to Chao Yu
Quoted 9 lines · Chao Yu

From: Chao Yu <[email protected]>

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.

Applied, thanks. (Apologies for the delay; this patch slipped through the cracks.)

- Ted

author
#3 lore raw
Quoted 8 lines · Theodore Ts'o
Quoted 7 lines · Chao Yu

From: Chao Yu <[email protected]>

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.

Quoted 5 lines
Quoted 2 lines

Applied, thanks. (Apologies for the delay; this patch slipped through the cracks.)

Ping, didn't see it in mainline, is this patch still under testing now?

Quoted 3 lines

- Ted

#4 lore raw
Quoted 9 lines · Chao Yu
Quoted 8 lines · Theodore Ts'o
Quoted 7 lines · Chao Yu

From: Chao Yu <[email protected]>

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.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Applied, thanks. (Apologies for the delay; this patch slipped through the cracks.)

Ping, didn't see it in mainline, is this patch still under testing now?

I'm sorry, I'm not sure how it got dropped, but it's not in mainline and I'm not sure how it got dropped from the ext4 tree.

It's now queued up in the dev tree.

Thanks for checking back,

- Ted

author
#5 lore raw
Quoted 16 lines · Theodore Ts'o
Quoted 15 lines · Chao Yu
Quoted 13 lines · Theodore Ts'o
Quoted 9 lines · Chao Yu

From: Chao Yu <[email protected]>

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.

Applied, thanks. (Apologies for the delay; this patch slipped through the cracks.)

Quoted 8 lines
Quoted 1 line

Ping, didn't see it in mainline, is this patch still under testing now?

I'm sorry, I'm not sure how it got dropped, but it's not in mainline and I'm not sure how it got dropped from the ext4 tree.

It's now queued up in the dev tree.

Thanks for checking back,

Thanks for merging! ;)

Quoted 3 lines

- Ted