[PATCH] DMA mapping leak in error path in __nvme_fc_init_requet()

[email protected]
Newsgroups org.infradead.lists.linux-nvme
Message-ID <[email protected]>
From: Wen Xiong <[email protected]>

In __nvme_fc_init_request(), if the first DMA mapping for cmddma succeeds
but the second DMA mapping for rspdma fails, the function returns an error
without unmapping the first successful DMA mapping. This causes a DMA
resource leak.

Fix this by unmapping cmddma before returning the error when rspdma
mapping fails.

Signed-off-by: Wen Xiong <[email protected]>
---
 drivers/nvme/host/fc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 68a5d971657b..7684fb053963 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -2129,6 +2129,8 @@ __nvme_fc_init_request(struct nvme_fc_ctrl *ctrl,
 	if (fc_dma_mapping_error(ctrl->lport->dev, op->fcp_req.rspdma)) {
 		dev_err(ctrl->dev,
 			"FCP Op failed - rspiu dma mapping failed.\n");
+		fc_dma_unmap_single(ctrl->lport->dev, op->fcp_req.cmddma,
+				sizeof(op->cmd_iu), DMA_TO_DEVICE);
 		ret = -EFAULT;
 	}
 
-- 
2.52.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.