nbd: Fix incorrect error handle when first_minor is illegal in nbd_dev_add
authorYe Bin <yebin10@huawei.com>
Tue, 2 Nov 2021 01:52:36 +0000 (09:52 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Apr 2022 18:58:59 +0000 (20:58 +0200)
[ Upstream commit 69beb62ff0d1723a750eebe1c4d01da573d7cd19 ]

If first_minor is illegal will goto out_free_idr label, this will miss
cleanup disk.

Fixes: b1a811633f73 ("block: nbd: add sanity check for first_minor")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/r/20211102015237.2309763-4-yebin10@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/nbd.c

index 946fdc1..4ae6c22 100644 (file)
@@ -1755,7 +1755,7 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
        disk->first_minor = index << part_shift;
        if (disk->first_minor < index || disk->first_minor > MINORMASK) {
                err = -EINVAL;
-               goto out_free_idr;
+               goto out_err_disk;
        }
 
        disk->minors = 1 << part_shift;