diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index beea23d04a70..11599b0061b1 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -165,8 +165,11 @@ void nvme_queue_scan(struct nvme_ctrl *ctrl) /* * Only new queue scan work when admin and IO queues are both alive */ - if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE && ctrl->tagset) - queue_work(nvme_wq, &ctrl->scan_work); + if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE && ctrl->tagset) { + nvme_get_ctrl(ctrl); + if (!queue_work(nvme_wq, &ctrl->scan_work)) + nvme_put_ctrl(ctrl); + } } /* @@ -4635,7 +4638,7 @@ static void nvme_scan_work(struct work_struct *work) /* No tagset on a live ctrl means IO queues could not created */ if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE || !ctrl->tagset) - return; + goto out; /* * Identify controller limits can change at controller reset due to @@ -4648,7 +4651,7 @@ static void nvme_scan_work(struct work_struct *work) if (ret < 0) { dev_warn(ctrl->device, "reading non-mdts-limits failed: %d\n", ret); - return; + goto out; } if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { @@ -4679,6 +4682,8 @@ static void nvme_scan_work(struct work_struct *work) /* Re-read the ANA log page to not miss updates */ queue_work(nvme_wq, &ctrl->ana_work); #endif +out: + nvme_put_ctrl(ctrl); } /*