Skip to content

Commit

Permalink
null_blk: fix ida error handling in null_add_dev()
Browse files Browse the repository at this point in the history
There needs to be some error checking if ida_simple_get() fails.
Also call ida_free() if there are errors later.

Fixes: 94bc02e ("nullb: use ida to manage index")
Signed-off-by: Dan Carpenter <[email protected]>
Link: https://lore.kernel.org/r/YtEhXsr6vJeoiYhd@kili
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Dan Carpenter authored and axboe committed Aug 2, 2022
1 parent c13cf14 commit ee452a8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/block/null_blk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2090,8 +2090,13 @@ static int null_add_dev(struct nullb_device *dev)
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, nullb->q);

mutex_lock(&lock);
nullb->index = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL);
dev->index = nullb->index;
rv = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL);
if (rv < 0) {
mutex_unlock(&lock);
goto out_cleanup_zone;
}
nullb->index = rv;
dev->index = rv;
mutex_unlock(&lock);

blk_queue_logical_block_size(nullb->q, dev->blocksize);
Expand All @@ -2117,7 +2122,7 @@ static int null_add_dev(struct nullb_device *dev)

rv = null_gendisk_register(nullb);
if (rv)
goto out_cleanup_zone;
goto out_ida_free;

mutex_lock(&lock);
list_add_tail(&nullb->list, &nullb_list);
Expand All @@ -2126,6 +2131,9 @@ static int null_add_dev(struct nullb_device *dev)
pr_info("disk %s created\n", nullb->disk_name);

return 0;

out_ida_free:
ida_free(&nullb_indexes, nullb->index);
out_cleanup_zone:
null_free_zoned_dev(dev);
out_cleanup_disk:
Expand Down

0 comments on commit ee452a8

Please sign in to comment.