summaryrefslogtreecommitdiff
path: root/drivers/block/ublk_drv.c
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2022-07-30 17:27:48 +0800
committerJens Axboe <axboe@kernel.dk>2022-08-02 21:13:40 -0600
commit93d71ec89d5fb2bc431fe7e0ff7ca819bf6dc601 (patch)
tree70a4a44f61d172bcca0c97b49d8d7f3c063837db /drivers/block/ublk_drv.c
parenta8ce5f52efce3b89ca82ce8798d0d061117465d2 (diff)
ublk_drv: fix ublk device leak in case that add_disk fails
->free_disk is only called after disk is added successfully, so drop ublk device reference in case of add_disk() failure. Fixes: 6d9e6dfdf3b2 ("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>
Diffstat (limited to 'drivers/block/ublk_drv.c')
-rw-r--r--drivers/block/ublk_drv.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 7ece4c2ef062..ae98e81b21ce 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -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;
}