diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-07-25 09:46:27 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-07-25 09:46:27 +0100 |
commit | 4ae5a5219287631e2b7bb804944b96088cbf7ca3 (patch) | |
tree | 41e270af14079820f4ecadc047c67df6aebbda67 | |
parent | e8424702c53e20d4fc0324a971f5b2bf2dc116fe (diff) | |
download | xen-4ae5a5219287631e2b7bb804944b96088cbf7ca3.tar.gz xen-4ae5a5219287631e2b7bb804944b96088cbf7ca3.tar.bz2 xen-4ae5a5219287631e2b7bb804944b96088cbf7ca3.zip |
vtd: change code style of pci.c file, and add spin_unlock(&pdev->lock)
when iommu_add_device() fails.
Signed-off-by: Weidong Han <weidong.han@intel.com>
-rw-r--r-- | xen/drivers/passthrough/pci.c | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 6309495f47..b38e04e908 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -34,11 +34,11 @@ struct pci_dev *alloc_pdev(u8 bus, u8 devfn) list_for_each_entry ( pdev, &alldevs_list, alldevs_list ) if ( pdev->bus == bus && pdev->devfn == devfn ) - return pdev; + return pdev; pdev = xmalloc(struct pci_dev); if ( !pdev ) - return NULL; + return NULL; *((u8*) &pdev->bus) = bus; *((u8*) &pdev->devfn) = devfn; @@ -63,12 +63,12 @@ struct pci_dev *pci_lock_pdev(int bus, int devfn) read_lock(&pcidevs_lock); list_for_each_entry ( pdev, &alldevs_list, alldevs_list ) if ( (pdev->bus == bus || bus == -1) && - (pdev->devfn == devfn || devfn == -1) ) - { - spin_lock(&pdev->lock); - read_unlock(&pcidevs_lock); - return pdev; - } + (pdev->devfn == devfn || devfn == -1) ) + { + spin_lock(&pdev->lock); + read_unlock(&pcidevs_lock); + return pdev; + } read_unlock(&pcidevs_lock); return NULL; @@ -81,15 +81,15 @@ struct pci_dev *pci_lock_domain_pdev(struct domain *d, int bus, int devfn) read_lock(&pcidevs_lock); list_for_each_entry ( pdev, &d->arch.pdev_list, domain_list ) { - spin_lock(&pdev->lock); + spin_lock(&pdev->lock); if ( (pdev->bus == bus || bus == -1) && - (pdev->devfn == devfn || devfn == -1) && - (pdev->domain == d) ) - { - read_unlock(&pcidevs_lock); - return pdev; - } - spin_unlock(&pdev->lock); + (pdev->devfn == devfn || devfn == -1) && + (pdev->domain == d) ) + { + read_unlock(&pcidevs_lock); + return pdev; + } + spin_unlock(&pdev->lock); } read_unlock(&pcidevs_lock); @@ -104,19 +104,24 @@ int pci_add_device(u8 bus, u8 devfn) write_lock(&pcidevs_lock); pdev = alloc_pdev(bus, devfn); if ( !pdev ) - goto out; + goto out; ret = 0; spin_lock(&pdev->lock); if ( !pdev->domain ) { - pdev->domain = dom0; - list_add(&pdev->domain_list, &dom0->arch.pdev_list); - ret = iommu_add_device(pdev); + pdev->domain = dom0; + ret = iommu_add_device(pdev); + if ( ret ) + { + spin_unlock(&pdev->lock); + goto out; + } + list_add(&pdev->domain_list, &dom0->arch.pdev_list); } spin_unlock(&pdev->lock); printk(XENLOG_DEBUG "PCI add device %02x:%02x.%x\n", bus, - PCI_SLOT(devfn), PCI_FUNC(devfn)); + PCI_SLOT(devfn), PCI_FUNC(devfn)); out: write_unlock(&pcidevs_lock); @@ -131,17 +136,17 @@ int pci_remove_device(u8 bus, u8 devfn) write_lock(&pcidevs_lock); list_for_each_entry ( pdev, &alldevs_list, alldevs_list ) if ( pdev->bus == bus && pdev->devfn == devfn ) - { - spin_lock(&pdev->lock); - ret = iommu_remove_device(pdev); - if ( pdev->domain ) - list_del(&pdev->domain_list); - pci_cleanup_msi(pdev); - free_pdev(pdev); - printk(XENLOG_DEBUG "PCI remove device %02x:%02x.%x\n", bus, - PCI_SLOT(devfn), PCI_FUNC(devfn)); - break; - } + { + spin_lock(&pdev->lock); + ret = iommu_remove_device(pdev); + if ( pdev->domain ) + list_del(&pdev->domain_list); + pci_cleanup_msi(pdev); + free_pdev(pdev); + printk(XENLOG_DEBUG "PCI remove device %02x:%02x.%x\n", bus, + PCI_SLOT(devfn), PCI_FUNC(devfn)); + break; + } write_unlock(&pcidevs_lock); return ret; @@ -171,14 +176,14 @@ static void dump_pci_devices(unsigned char ch) list_for_each_entry ( pdev, &alldevs_list, alldevs_list ) { - spin_lock(&pdev->lock); + spin_lock(&pdev->lock); printk("%02x:%02x.%x - dom %-3d - MSIs < ", pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), pdev->domain ? pdev->domain->domain_id : -1); - list_for_each_entry ( msi, &pdev->msi_list, list ) - printk("%d ", msi->vector); - printk(">\n"); - spin_unlock(&pdev->lock); + list_for_each_entry ( msi, &pdev->msi_list, list ) + printk("%d ", msi->vector); + printk(">\n"); + spin_unlock(&pdev->lock); } read_unlock(&pcidevs_lock); |