[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] 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.

Signed-off-by: Teshan Kannangara <tpk.teshan@xxxxxxxxx>
---
 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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.