Skip to contentSkip to conversation

xen/platform-pci: Disable device before releasing PCI regions

PATCH In review Teshan Kannangara 2 participants 2 messages Oct 13 – Nov 9 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/platform-pci: Disable device before releasing PCI regions

The probe error paths release the PCI regions before disabling the device. Documentation/PCI/pci.rst specifies that drivers should disable the device before releasing its regions to prevent devices from colliding on the same address range.

Track successfully requested BARs in a bitmask and use a common cleanup path to disable the device before releasing those regions.

---
 drivers/xen/platform-pci.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/xen/platform-pci.c +7 -7
index f2438232518c..a12ac57274a6 100644
@@ -95,6 +95,7 @@ static int platform_pci_probe(struct pci_dev *pdev,
 			      const struct pci_device_id *ent)
 {
 	int i, ret;
+	int requested_bars = 0;
 	long ioaddr;
 	long mmio_addr, mmio_len;
 	unsigned int max_nr_gframes;
@@ -115,16 +116,18 @@ static int platform_pci_probe(struct pci_dev *pdev,
 	if (mmio_addr == 0 || ioaddr == 0) {
 		dev_err(&pdev->dev, "no resources found\n");
 		ret = -ENOENT;
-		goto pci_out;
+		goto out;
 	}
 
 	ret = pci_request_region(pdev, 1, DRV_NAME);
 	if (ret < 0)
-		goto pci_out;
+		goto out;
+	requested_bars |= BIT(1);
 
 	ret = pci_request_region(pdev, 0, DRV_NAME);
 	if (ret < 0)
-		goto mem_out;
+		goto out;
+	requested_bars |= BIT(0);
 
 	platform_mmio = mmio_addr;
 	platform_mmiolen = mmio_len;
@@ -165,11 +168,8 @@ static int platform_pci_probe(struct pci_dev *pdev,
 	if (!xen_have_vector_callback)
 		free_irq(pdev->irq, pdev);
 out:
-	pci_release_region(pdev, 0);
-mem_out:
-	pci_release_region(pdev, 1);
-pci_out:
 	pci_disable_device(pdev);
+	pci_release_selected_regions(pdev, requested_bars);
 	return ret;
 }
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Teshan Kannangara

The probe error paths release the PCI regions before disabling the device. Documentation/PCI/pci.rst specifies that drivers should disable the device before releasing its regions to prevent devices from colliding on the same address range.

Track successfully requested BARs in a bitmask and use a common cleanup path to disable the device before releasing those regions.

Juergen