PCI/P2PDMA: fix the gen_pool_add_virt() failure path
authorDan Williams <[email protected]>
Thu, 13 Jun 2019 22:56:24 +0000 (15:56 -0700)
committerLinus Torvalds <[email protected]>
Fri, 14 Jun 2019 03:34:56 +0000 (17:34 -1000)
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: http://lkml.kernel.org/r/155727337603.292046.13101332703665246702.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <[email protected]>
Fixes: 52916982af48 ("PCI/P2PDMA: Support peer-to-peer memory")
Reviewed-by: Ira Weiny <[email protected]>
Acked-by: Bjorn Helgaas <[email protected]>
Reviewed-by: Logan Gunthorpe <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Jérôme Glisse" <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
drivers/pci/p2pdma.c

index 742928d0053ec79bf886a24939db4cdc799096d8..d5736b31ce6602f7738d74480629b305a91816fc 100644 (file)
@@ -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",
                 &pgmap->res);
 
        return 0;
 
+pages_free:
+       devm_memunmap_pages(&pdev->dev, pgmap);
 pgmap_free:
        devm_kfree(&pdev->dev, pgmap);
        return error;