提交 f85cd1a9 编写于 作者: D Dan Carpenter 提交者: Zheng Zengkai

null_blk: fix ida error handling in null_add_dev()

stable inclusion
from stable-v5.10.137
commit 7a4b46784a7b27b5ceb28bc816ea188d6d035dfa
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60PLB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=7a4b46784a7b27b5ceb28bc816ea188d6d035dfa

--------------------------------

[ Upstream commit ee452a8d ]

There needs to be some error checking if ida_simple_get() fails.
Also call ida_free() if there are errors later.

Fixes: 94bc02e3 ("nullb: use ida to manage index")
Signed-off-by: NDan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YtEhXsr6vJeoiYhd@kiliSigned-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 77daec38
...@@ -1876,8 +1876,13 @@ static int null_add_dev(struct nullb_device *dev) ...@@ -1876,8 +1876,13 @@ static int null_add_dev(struct nullb_device *dev)
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, nullb->q); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, nullb->q);
mutex_lock(&lock); mutex_lock(&lock);
nullb->index = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL); rv = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL);
dev->index = nullb->index; if (rv < 0) {
mutex_unlock(&lock);
goto out_cleanup_zone;
}
nullb->index = rv;
dev->index = rv;
mutex_unlock(&lock); mutex_unlock(&lock);
blk_queue_logical_block_size(nullb->q, dev->blocksize); blk_queue_logical_block_size(nullb->q, dev->blocksize);
...@@ -1889,13 +1894,16 @@ static int null_add_dev(struct nullb_device *dev) ...@@ -1889,13 +1894,16 @@ static int null_add_dev(struct nullb_device *dev)
rv = null_gendisk_register(nullb); rv = null_gendisk_register(nullb);
if (rv) if (rv)
goto out_cleanup_zone; goto out_ida_free;
mutex_lock(&lock); mutex_lock(&lock);
list_add_tail(&nullb->list, &nullb_list); list_add_tail(&nullb->list, &nullb_list);
mutex_unlock(&lock); mutex_unlock(&lock);
return 0; return 0;
out_ida_free:
ida_free(&nullb_indexes, nullb->index);
out_cleanup_zone: out_cleanup_zone:
null_free_zoned_dev(dev); null_free_zoned_dev(dev);
out_cleanup_blk_queue: out_cleanup_blk_queue:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册