]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ublk_drv: fix ublk device leak in case that add_disk fails
authorMing Lei <ming.lei@redhat.com>
Sat, 30 Jul 2022 09:27:48 +0000 (17:27 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 3 Aug 2022 03:13:40 +0000 (21:13 -0600)
->free_disk is only called after disk is added successfully, so
drop ublk device reference in case of add_disk() failure.

Fixes: 805c1c087e93 ("ublk: defer disk allocation")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20220730092750.1118167-3-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index 7ece4c2ef0620fa95c6d0cd345897845af2693b9..ae98e81b21ceff09183341137b017b329f207056 100644 (file)
@@ -1190,6 +1190,11 @@ static int ublk_ctrl_start_dev(struct io_uring_cmd *cmd)
        get_device(&ub->cdev_dev);
        ret = add_disk(disk);
        if (ret) {
+               /*
+                * Has to drop the reference since ->free_disk won't be
+                * called in case of add_disk failure.
+                */
+               ublk_put_device(ub);
                put_disk(disk);
                goto out_unlock;
        }