All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ntb: epf: fix PCI resource cleanup on init error path
@ 2026-07-02  7:06 Shashwat Agrawal
  2026-07-02  7:16 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Shashwat Agrawal @ 2026-07-02  7:06 UTC (permalink / raw)
  To: Jon Mason; +Cc: Dave Jiang, Allen Hubbe, ntb, linux-kernel, Shashwat Agrawal

After pci_request_regions() succeeds, failures from setting the DMA
mask or mapping BARs jumped to a path that only called
pci_disable_device(). PCI regions were left claimed, and any BARs
already mapped with pci_iomap() were not unmapped.

Release regions on those failures and unwind iomaps in reverse order.
When peer scratchpads share the config BAR, do not pci_iounmap() the
offset pointer, consistent with ntb_epf_deinit_pci().

Signed-off-by: Shashwat Agrawal <shashwatagrawal473@gmail.com>
---
 drivers/ntb/hw/epf/ntb_hw_epf.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
index c47607d4f8a7..b42fb5f9fa75 100644
--- a/drivers/ntb/hw/epf/ntb_hw_epf.c
+++ b/drivers/ntb/hw/epf/ntb_hw_epf.c
@@ -683,7 +683,7 @@ static int ntb_epf_init_pci(struct ntb_epf_dev *ndev,
 		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
 		if (ret) {
 			dev_err(dev, "Cannot set DMA mask\n");
-			goto err_pci_regions;
+			goto err_dma_mask;
 		}
 		dev_warn(&pdev->dev, "Cannot DMA highmem\n");
 	}
@@ -691,7 +691,7 @@ static int ntb_epf_init_pci(struct ntb_epf_dev *ndev,
 	ndev->ctrl_reg = pci_iomap(pdev, ndev->barno_map[BAR_CONFIG], 0);
 	if (!ndev->ctrl_reg) {
 		ret = -EIO;
-		goto err_pci_regions;
+		goto err_dma_mask;
 	}
 
 	if (ndev->barno_map[BAR_PEER_SPAD] != ndev->barno_map[BAR_CONFIG]) {
@@ -699,7 +699,7 @@ static int ntb_epf_init_pci(struct ntb_epf_dev *ndev,
 						ndev->barno_map[BAR_PEER_SPAD], 0);
 		if (!ndev->peer_spad_reg) {
 			ret = -EIO;
-			goto err_pci_regions;
+			goto err_ctrl_map;
 		}
 	} else {
 		spad_sz = 4 * readl(ndev->ctrl_reg + NTB_EPF_SPAD_COUNT);
@@ -710,14 +710,20 @@ static int ntb_epf_init_pci(struct ntb_epf_dev *ndev,
 	ndev->db_reg = pci_iomap(pdev, ndev->barno_map[BAR_DB], 0);
 	if (!ndev->db_reg) {
 		ret = -EIO;
-		goto err_pci_regions;
+		goto err_peer_map;
 	}
 
 	return 0;
 
+err_peer_map:
+	if (ndev->barno_map[BAR_PEER_SPAD] != ndev->barno_map[BAR_CONFIG])
+		pci_iounmap(pdev, ndev->peer_spad_reg);
+err_ctrl_map:
+	pci_iounmap(pdev, ndev->ctrl_reg);
+err_dma_mask:
+	pci_release_regions(pdev);
 err_pci_regions:
 	pci_disable_device(pdev);
-
 err_pci_enable:
 	pci_set_drvdata(pdev, NULL);
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-02  7:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02  7:06 [PATCH] ntb: epf: fix PCI resource cleanup on init error path Shashwat Agrawal
2026-07-02  7:16 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.