In ublk_stop_dev(), if ublk device state becomes UBLK_S_DEV_DEAD, we will return immediately. This way is correct, but not enough, because ublk device may transition to other state, such UBLK_S_DEV_QUIECED, when it may have been stopped already. Then kernel panic is triggered. Fix it by checking ->ub_disk directly, this way is simpler and effective since ub->mutex covers ->ub_disk change. Fixes: bbae8d1f526b ("ublk_drv: consider recovery feature in aborting mechanism") Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> --- drivers/block/ublk_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index cdb1543fa4a9..15de4881f25b 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -1784,7 +1784,7 @@ static void ublk_stop_dev(struct ublk_device *ub) struct gendisk *disk; mutex_lock(&ub->mutex); - if (ub->dev_info.state == UBLK_S_DEV_DEAD) + if (!ub->ub_disk) goto unlock; if (ublk_nosrv_dev_should_queue_io(ub)) { if (ub->dev_info.state == UBLK_S_DEV_LIVE) -- 2.47.0