Skip to contentSkip to conversation

PCI/P2PDMA: Fix freeing dev_pagemap on error

PATCH Superseded Keith Busch 2 participants 4 messages Oct 12, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI/P2PDMA: Fix freeing dev_pagemap on error

The devres_free() API is only to be used after the resource has been unlinked from the device tracking it. Calling this functino directly will hit a kernel BUG_ON. This patch fixes this to use the managed resource release function, devm_kfree().

Fixes 1380472e7b855 ("PCI/P2PDMA: Support peer-to-peer memory")
Cc Logan Gunthorpe <[email protected]>
---
 drivers/pci/p2pdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/p2pdma.c +1 -1
index da66c7e31730..9c56a10eff15 100644
@@ -222,7 +222,7 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
 	return 0;
 
 pgmap_free:
-	devres_free(pgmap);
+	devm_kfree(&pci->dev, pgmap);
 	return error;
 }
 EXPORT_SYMBOL_GPL(pci_p2pdma_add_resource);
Signature · 1 line
2.14.4
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Keith Busch

The devres_free() API is only to be used after the resource has been unlinked from the device tracking it. Calling this functino directly will hit a kernel BUG_ON. This patch fixes this to use the managed resource release function, devm_kfree().

Fixes 1380472e7b855 ("PCI/P2PDMA: Support peer-to-peer memory")
Cc Logan Gunthorpe <[email protected]>

Oops, yes, nice catch! Thanks!

Quoted 18 lines
---
 drivers/pci/p2pdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/p2pdma.c +1 -1
index da66c7e31730..9c56a10eff15 100644
@@ -222,7 +222,7 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
 	return 0;
 
 pgmap_free:
-	devres_free(pgmap);
+	devm_kfree(&pci->dev, pgmap);
 	return error;
 }
 EXPORT_SYMBOL_GPL(pci_p2pdma_add_resource);
#2 lore raw
Quoted 11 lines · Logan Gunthorpe
Quoted 8 lines · Keith Busch

The devres_free() API is only to be used after the resource has been unlinked from the device tracking it. Calling this functino directly will hit a kernel BUG_ON. This patch fixes this to use the managed resource release function, devm_kfree().

Fixes 1380472e7b855 ("PCI/P2PDMA: Support peer-to-peer memory")
Cc Logan Gunthorpe <[email protected]>

Oops, yes, nice catch! Thanks!

Yeah, I hit the bug after an nvme controller reset. The nvme driver tries to add its CMB memory a second time, and it's correctly detected as an error by devm_memremap_pages(), but I'm also thinking nvme should have known better too.

Anyway, this patch (its v2, really) is the simple error handling fix, but there will be a follow up nvme patch to avoid the error in the first place. :)

#3 lore raw
In reply to Keith Busch
Quoted 17 lines · Keith Busch

The devres_free() API is only to be used after the resource has been unlinked from the device tracking it. Calling this functino directly will hit a kernel BUG_ON. This patch fixes this to use the managed resource release function, devm_kfree().

Fixes 1380472e7b855 ("PCI/P2PDMA: Support peer-to-peer memory")
Cc Logan Gunthorpe <[email protected]>
---
 drivers/pci/p2pdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/p2pdma.c +0 -0
index da66c7e31730..9c56a10eff15 100644

drivers/pci/p2pdma.c int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size, · line 225

Quoted 5 lines
drivers/pci/p2pdma.c +1 -1
@@ -222,7 +222,7 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
 	return 0;
 
 pgmap_free:
-	devres_free(pgmap);
+	devm_kfree(&pci->dev, pgmap);
                    ^^^

That should be 'pdev', not 'pci'. I need to slow down the workflow, I'm pointing send-email to the wrong patches again...