]> git.baikalelectronics.ru Git - kernel.git/commit
ublk_drv: fix error handling of ublk_add_dev
authorChristoph Hellwig <hch@lst.de>
Fri, 22 Jul 2022 10:38:16 +0000 (18:38 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 22 Jul 2022 15:22:53 +0000 (09:22 -0600)
commite793e7bac6fa3538435ccb6f365a830449832bc1
tree4e7689f3499b0d4daf0fc25815854a777de8b66a
parent125590b861d3a0ae4b1d95066dd4f1314d223b4e
ublk_drv: fix error handling of ublk_add_dev

__ublk_destroy_dev() is called for handling error in ublk_add_dev(),
but either tagset isn't allocated or mutex isn't initialized.

So fix the issue by letting replacing ublk_add_dev with a
ublk_add_tag_set function that is much more limited in scope and
instead unwind every single step directly in ublk_ctrl_add_dev.
To allow for this refactor the device freeing so that there is
a helper for freeing the device number instead of coupling that
with freeing the mutex and the memory.

Note that this now copies the dev_info to userspace before adding
the character device.  This not only simplifies the erro handling
in ublk_ctrl_add_dev, but also means that the character device
can only be seen by userspace if the device addition succeeded.

Based on a patch from Ming Lei.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20220722103817.631258-2-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c