[PATCH] nvme-pci: fix dma mapping leak on data setup error
Keith Busch
kbusch at kernel.org
Tue May 19 15:33:11 PDT 2026
On Tue, May 19, 2026 at 01:06:14PM -0700, Keith Busch wrote:
> - if (!nvme_pci_prp_save_mapping(req, nvmeq->dev->dev, iter))
> + if (!nvme_pci_prp_save_mapping(req, nvmeq->dev->dev, iter)) {
> + dma_unmap_phys(nvmeq->dev->dev, iter->addr, iter->len,
> + rq_dma_dir(req),
> + iod->flags & IOD_DATA_MMIO ? DMA_ATTR_MMIO : 0);
> return iter->status;
> + }
>
> /*
> * PRP1 always points to the start of the DMA transfers.
> @@ -1112,6 +1116,7 @@ static blk_status_t nvme_pci_setup_data_prp(struct request *req,
> dev_err_once(nvmeq->dev->dev,
> "Incorrectly formed request for payload:%d nents:%d\n",
> blk_rq_payload_bytes(req), blk_rq_nr_phys_segments(req));
> + nvme_unmap_data(req);
> return BLK_STS_IOERR;
> }
>
> @@ -1155,8 +1160,13 @@ static blk_status_t nvme_pci_setup_data_sgl(struct request *req,
>
> sg_list = dma_pool_alloc(nvme_dma_pool(nvmeq, iod), GFP_ATOMIC,
> &sgl_dma);
> - if (!sg_list)
> + if (!sg_list) {
> + dma_unmap_phys(nvmeq->dev->dev, iter->addr, iter->len,
> + rq_dma_dir(req),
> + iod->flags & IOD_DATA_MMIO ? DMA_ATTR_MMIO : 0);
> return BLK_STS_RESOURCE;
> + }
Oh, these need to check dma_need_unmap() first. I'll send a v2.
More information about the Linux-nvme
mailing list