diff options
authorDan Williams <>2019-06-13 15:56:24 -0700
committerLinus Torvalds <>2019-06-13 17:34:56 -1000
commite615a191216e3fb4e9c0d239007f2b0cd48f28bf (patch)
parent2e3f139e8ecebf177fe01299285a56855e93fb84 (diff)
PCI/P2PDMA: fix the gen_pool_add_virt() failure path
The pci_p2pdma_add_resource() implementation immediately frees the pgmap if gen_pool_add_virt() fails. However, that means that when @dev triggers a devres release devm_memremap_pages_release() will crash trying to access the freed @pgmap. Use the new devm_memunmap_pages() to manually free the mapping in the error path. Link: Signed-off-by: Dan Williams <> Fixes: 52916982af48 ("PCI/P2PDMA: Support peer-to-peer memory") Reviewed-by: Ira Weiny <> Acked-by: Bjorn Helgaas <> Reviewed-by: Logan Gunthorpe <> Cc: Christoph Hellwig <> Cc: Greg Kroah-Hartman <> Cc: "Jérôme Glisse" <> Cc: "Rafael J. Wysocki" <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index 742928d0053e..d5736b31ce66 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -208,13 +208,15 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
pci_bus_address(pdev, bar) + offset,
resource_size(&pgmap->res), dev_to_node(&pdev->dev));
if (error)
- goto pgmap_free;
+ goto pages_free;
pci_info(pdev, "added peer-to-peer DMA memory %pR\n",
return 0;
+ devm_memunmap_pages(&pdev->dev, pgmap);
devm_kfree(&pdev->dev, pgmap);
return error;