Skip to content

Commit

Permalink
bcache: Remove unnecessary NULL point check in node allocations
Browse files Browse the repository at this point in the history
Due to the previous fix of __bch_btree_node_alloc, the return value will
never be a NULL pointer. So IS_ERR is enough to handle the failure
situation. Fix it by replacing IS_ERR_OR_NULL check by an IS_ERR check.

Fixes: cafe563 ("bcache: A block layer cache")
Cc: stable@vger.kernel.org
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
Signed-off-by: Coly Li <colyli@suse.de>
Link: https://lore.kernel.org/r/20230615121223.22502-5-colyli@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
bluesheep1337 authored and axboe committed Jun 15, 2023
1 parent ccb8c3b commit 028ddca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions drivers/md/bcache/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ static struct btree *btree_node_alloc_replacement(struct btree *b,
{
struct btree *n = bch_btree_node_alloc(b->c, op, b->level, b->parent);

if (!IS_ERR_OR_NULL(n)) {
if (!IS_ERR(n)) {
mutex_lock(&n->write_lock);
bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort);
bkey_copy_key(&n->key, &b->key);
Expand Down Expand Up @@ -1340,7 +1340,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op,
memset(new_nodes, 0, sizeof(new_nodes));
closure_init_stack(&cl);

while (nodes < GC_MERGE_NODES && !IS_ERR_OR_NULL(r[nodes].b))
while (nodes < GC_MERGE_NODES && !IS_ERR(r[nodes].b))
keys += r[nodes++].keys;

blocks = btree_default_blocks(b->c) * 2 / 3;
Expand All @@ -1352,7 +1352,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op,

for (i = 0; i < nodes; i++) {
new_nodes[i] = btree_node_alloc_replacement(r[i].b, NULL);
if (IS_ERR_OR_NULL(new_nodes[i]))
if (IS_ERR(new_nodes[i]))
goto out_nocoalesce;
}

Expand Down Expand Up @@ -1487,7 +1487,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op,
bch_keylist_free(&keylist);

for (i = 0; i < nodes; i++)
if (!IS_ERR_OR_NULL(new_nodes[i])) {
if (!IS_ERR(new_nodes[i])) {
btree_node_free(new_nodes[i]);
rw_unlock(true, new_nodes[i]);
}
Expand Down Expand Up @@ -1669,7 +1669,7 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op,
if (should_rewrite) {
n = btree_node_alloc_replacement(b, NULL);

if (!IS_ERR_OR_NULL(n)) {
if (!IS_ERR(n)) {
bch_btree_node_write_sync(n);

bch_btree_set_root(n);
Expand Down
4 changes: 2 additions & 2 deletions drivers/md/bcache/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ static void cache_set_flush(struct closure *cl)
if (!IS_ERR_OR_NULL(c->gc_thread))
kthread_stop(c->gc_thread);

if (!IS_ERR_OR_NULL(c->root))
if (!IS_ERR(c->root))
list_add(&c->root->list, &c->btree_cache);

/*
Expand Down Expand Up @@ -2087,7 +2087,7 @@ static int run_cache_set(struct cache_set *c)

err = "cannot allocate new btree root";
c->root = __bch_btree_node_alloc(c, NULL, 0, true, NULL);
if (IS_ERR_OR_NULL(c->root))
if (IS_ERR(c->root))
goto err;

mutex_lock(&c->root->write_lock);
Expand Down

0 comments on commit 028ddca

Please sign in to comment.