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: 6d9e6dfdf3 ("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>
This commit is contained in:
@@ -1190,6 +1190,11 @@ static int ublk_ctrl_start_dev(struct io_uring_cmd *cmd)
|
|||||||
get_device(&ub->cdev_dev);
|
get_device(&ub->cdev_dev);
|
||||||
ret = add_disk(disk);
|
ret = add_disk(disk);
|
||||||
if (ret) {
|
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);
|
put_disk(disk);
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user