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

Teshan Kannangara posted 1 patch 1 month, 1 week ago
There is a newer version of this series
drivers/xen/platform-pci.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
[PATCH] xen/platform-pci: Disable device before releasing PCI regions
Posted by Teshan Kannangara 1 month, 1 week ago
   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.

Signed-off-by: Teshan Kannangara <tpk.teshan@gmail.com>
---
 drivers/xen/platform-pci.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c
index f2438232518c..a12ac57274a6 100644
--- a/drivers/xen/platform-pci.c
+++ b/drivers/xen/platform-pci.c
@@ -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;
 }
 
-- 
2.53.0
Re: [PATCH] xen/platform-pci: Disable device before releasing PCI regions
Posted by Juergen Gross 2 weeks ago
On 13.10.26 07:36, Teshan Kannangara wrote:
>     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.
> 
> Signed-off-by: Teshan Kannangara <tpk.teshan@gmail.com>
Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen