Skip to contentSkip to conversation

md: bcache: check the return value of mempool_alloc() in bch_btree_node_read_done()

PATCH Superseded Jia-Ju Bai 2 participants 2 messages Feb 25, 2022 – Mar 2, 2022 bcache (block layer cache)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 md: bcache: check the return value of mempool_alloc() in bch_btree_node_read_done()

The function mempool_alloc() in bch_btree_node_read_done() can fail, so its return value should be checked.

Fixes d19936a26658 ("bcache: convert to bioset_init()/mempool_init()")
---
 drivers/md/bcache/btree.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/bcache/btree.c +2 -0
index 88c573eeb598..fb8b7dd6bcc2 100644
@@ -157,6 +157,8 @@ void bch_btree_node_read_done(struct btree *b)
 	 * See the comment arount cache_set->fill_iter.
 	 */
 	iter = mempool_alloc(&b->c->fill_iter, GFP_NOIO);
+	if (!iter)
+		return;
 	iter->size = b->c->cache->sb.bucket_size / b->c->cache->sb.block_size;
 	iter->used = 0;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 15 lines · Jia-Ju Bai

The function mempool_alloc() in bch_btree_node_read_done() can fail, so its return value should be checked.

Fixes d19936a26658 ("bcache: convert to bioset_init()/mempool_init()")
---
  drivers/md/bcache/btree.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/md/bcache/btree.c +0 -0
index 88c573eeb598..fb8b7dd6bcc2 100644

drivers/md/bcache/btree.c void bch_btree_node_read_done(struct btree *b) · line 161

Quoted 5 lines
drivers/md/bcache/btree.c +2 -0
@@ -157,6 +157,8 @@ void bch_btree_node_read_done(struct btree *b)
  	 * See the comment arount cache_set->fill_iter.
  	 */
  	iter = mempool_alloc(&b->c->fill_iter, GFP_NOIO);
+	if (!iter)
+		return;

This is unnecessary, mempool_alloc() doesn't return NULL in this condition.

Coly Li

Quoted 3 lines
drivers/md/bcache/btree.c +0 -0
  	iter->size = b->c->cache->sb.bucket_size / b->c->cache->sb.block_size;
  	iter->used = 0;