Skip to content

Commit 93d71ec

Browse files
Ming Leiaxboe
authored andcommitted
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: 6d9e6df ("ublk: defer disk allocation") Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent a8ce5f5 commit 93d71ec

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/block/ublk_drv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,11 @@ static int ublk_ctrl_start_dev(struct io_uring_cmd *cmd)
11901190
get_device(&ub->cdev_dev);
11911191
ret = add_disk(disk);
11921192
if (ret) {
1193+
/*
1194+
* Has to drop the reference since ->free_disk won't be
1195+
* called in case of add_disk failure.
1196+
*/
1197+
ublk_put_device(ub);
11931198
put_disk(disk);
11941199
goto out_unlock;
11951200
}

0 commit comments

Comments
 (0)