The patch titled Subject: PCI/P2PDMA: fix the gen_pool_add_virt() failure path has been added to the -mm tree. Its filename is pci-p2pdma-fix-the-gen_pool_add_virt-failure-path.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/pci-p2pdma-fix-the-gen_pool_add_virt-failure-path.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/pci-p2pdma-fix-the-gen_pool_add_virt-failure-path.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Dan Williams <dan.j.williams@xxxxxxxxx> Subject: 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: http://lkml.kernel.org/r/155727337603.292046.13101332703665246702.stgit@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx> Fixes: 52916982af48 ("PCI/P2PDMA: Support peer-to-peer memory") Reviewed-by: Ira Weiny <ira.weiny@xxxxxxxxx> Acked-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx> Reviewed-by: Logan Gunthorpe <logang@xxxxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: "Jérôme Glisse" <jglisse@xxxxxxxxxx> Cc: "Rafael J. Wysocki" <rafael@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- drivers/pci/p2pdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/pci/p2pdma.c~pci-p2pdma-fix-the-gen_pool_add_virt-failure-path +++ a/drivers/pci/p2pdma.c @@ -208,13 +208,15 @@ int pci_p2pdma_add_resource(struct pci_d 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; _ Patches currently in -mm which might be from dan.j.williams@xxxxxxxxx are drivers-base-devres-introduce-devm_release_action.patch mm-devm_memremap_pages-introduce-devm_memunmap_pages.patch pci-p2pdma-fix-the-gen_pool_add_virt-failure-path.patch lib-genalloc-introduce-chunk-owners.patch pci-p2pdma-track-pgmap-references-per-resource-not-globally.patch mm-devm_memremap_pages-fix-final-page-put-race.patch