Skip to content

Commit 80fca8a

Browse files
bluesheep1337axboe
authored andcommitted
bcache: Fix __bch_btree_node_alloc to make the failure behavior consistent
In some specific situations, the return value of __bch_btree_node_alloc may be NULL. This may lead to a potential NULL pointer dereference in caller function like a calling chain : btree_split->bch_btree_node_alloc->__bch_btree_node_alloc. Fix it by initializing the return value in __bch_btree_node_alloc. Fixes: cafe563 ("bcache: A block layer cache") Cc: [email protected] Signed-off-by: Zheng Wang <[email protected]> Signed-off-by: Coly Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 028ddca commit 80fca8a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/md/bcache/btree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,12 @@ struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op,
10901090
struct btree *parent)
10911091
{
10921092
BKEY_PADDED(key) k;
1093-
struct btree *b = ERR_PTR(-EAGAIN);
1093+
struct btree *b;
10941094

10951095
mutex_lock(&c->bucket_lock);
10961096
retry:
1097+
/* return ERR_PTR(-EAGAIN) when it fails */
1098+
b = ERR_PTR(-EAGAIN);
10971099
if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, wait))
10981100
goto err;
10991101

0 commit comments

Comments
 (0)