From: Ming Lei Date: Sat, 30 Jul 2022 09:27:48 +0000 (+0800) Subject: ublk_drv: fix ublk device leak in case that add_disk fails X-Git-Tag: v6.6.17~6887^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93d71ec89d5fb2bc431fe7e0ff7ca819bf6dc601;p=platform%2Fkernel%2Flinux-rpi.git 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 Signed-off-by: Ming Lei Link: https://lore.kernel.org/r/20220730092750.1118167-3-ming.lei@redhat.com Signed-off-by: Jens Axboe --- 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; }