From: David Milburn Date: Mon, 18 May 2020 18:59:55 +0000 (-0500) Subject: nvmet: cleanups the loop in nvmet_async_events_process X-Git-Tag: v5.7.7~208 X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=c91f052a8fb7d533c7f0be32b3f33f247cd898d2;p=wrapfs-4.13.y.git nvmet: cleanups the loop in nvmet_async_events_process [ Upstream commit 1cdf9f7670a7d74e27177d5c390c2f8b3b9ba338 ] Based-on-a-patch-by: Christoph Hellwig Tested-by: Yi Zhang Signed-off-by: David Milburn Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index aa5ca222c6f5..ac7ae031ce78 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -134,15 +134,10 @@ static void nvmet_async_events_process(struct nvmet_ctrl *ctrl, u16 status) struct nvmet_async_event *aen; struct nvmet_req *req; - while (1) { - mutex_lock(&ctrl->lock); - aen = list_first_entry_or_null(&ctrl->async_events, - struct nvmet_async_event, entry); - if (!aen || !ctrl->nr_async_event_cmds) { - mutex_unlock(&ctrl->lock); - break; - } - + mutex_lock(&ctrl->lock); + while (ctrl->nr_async_event_cmds && !list_empty(&ctrl->async_events)) { + aen = list_first_entry(&ctrl->async_events, + struct nvmet_async_event, entry); req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds]; if (status == 0) nvmet_set_result(req, nvmet_async_event_result(aen)); @@ -152,7 +147,9 @@ static void nvmet_async_events_process(struct nvmet_ctrl *ctrl, u16 status) mutex_unlock(&ctrl->lock); nvmet_req_complete(req, status); + mutex_lock(&ctrl->lock); } + mutex_unlock(&ctrl->lock); } static void nvmet_async_events_free(struct nvmet_ctrl *ctrl)