- 2.6.17 port work build breaks, but the patch set is relativly stable
[linux-flexiantxendom0-3.2.10.git] / drivers / pci / msi.c
index 4f8034e..9855c4c 100644 (file)
@@ -103,9 +103,9 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
        switch (entry->msi_attrib.type) {
        case PCI_CAP_ID_MSI:
        {
-               int pos;
+               int pos = pci_find_capability(entry->dev, PCI_CAP_ID_MSI);
 
-               if (!(pos = pci_find_capability(entry->dev, PCI_CAP_ID_MSI)))
+               if (!pos)
                        return;
 
                pci_read_config_dword(entry->dev, msi_lower_address_reg(pos),
@@ -347,9 +347,9 @@ static int assign_msi_vector(void)
 
 static int get_new_vector(void)
 {
-       int vector;
+       int vector = assign_msi_vector();
 
-       if ((vector = assign_msi_vector()) > 0)
+       if (vector > 0)
                set_intr_gate(vector, interrupt[vector]);
 
        return vector;
@@ -369,7 +369,8 @@ static int msi_init(void)
                return status;
        }
 
-       if ((status = msi_cache_init()) < 0) {
+       status = msi_cache_init();
+       if (status < 0) {
                pci_msi_enable = 0;
                printk(KERN_WARNING "PCI: MSI cache init failed\n");
                return status;
@@ -716,10 +717,12 @@ static int msi_capability_init(struct pci_dev *dev)
        pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
        pci_read_config_word(dev, msi_control_reg(pos), &control);
        /* MSI Entry Initialization */
-       if (!(entry = alloc_msi_entry()))
+       entry = alloc_msi_entry();
+       if (!entry)
                return -ENOMEM;
 
-       if ((vector = get_msi_vector(dev)) < 0) {
+       vector = get_msi_vector(dev);
+       if (vector < 0) {
                kmem_cache_free(msi_cachep, entry);
                return -EBUSY;
        }
@@ -789,8 +792,11 @@ static int msix_capability_init(struct pci_dev *dev,
                entry = alloc_msi_entry();
                if (!entry)
                        break;
-               if ((vector = get_msi_vector(dev)) < 0)
+               vector = get_msi_vector(dev);
+               if (vector < 0) {
+                       kmem_cache_free(msi_cachep, entry);
                        break;
+               }
 
                j = entries[i].entry;
                entries[i].vector = vector;
@@ -873,19 +879,22 @@ int pci_enable_msi(struct pci_dev* dev)
 
        temp = dev->irq;
 
-       if ((status = msi_init()) < 0)
+       status = msi_init();
+       if (status < 0)
                return status;
 
-       if (!(pos = pci_find_capability(dev, PCI_CAP_ID_MSI)))
+       pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
+       if (!pos)
                return -EINVAL;
 
+       pci_read_config_word(dev, msi_control_reg(pos), &control);
+       if (control & PCI_MSI_FLAGS_ENABLE)
+               return 0;                       /* Already in MSI mode */
+
        if (!msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
                /* Lookup Sucess */
                unsigned long flags;
 
-               pci_read_config_word(dev, msi_control_reg(pos), &control);
-               if (control & PCI_MSI_FLAGS_ENABLE)
-                       return 0;       /* Already in MSI mode */
                spin_lock_irqsave(&msi_lock, flags);
                if (!vector_irq[dev->irq]) {
                        msi_desc[dev->irq]->msi_attrib.state = 0;
@@ -900,8 +909,8 @@ int pci_enable_msi(struct pci_dev* dev)
                dev->irq = temp;
        }
        /* Check whether driver already requested for MSI-X vectors */
-       if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 &&
-               !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
+       pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+       if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
                        printk(KERN_INFO "PCI: %s: Can't enable MSI.  "
                               "Device already has MSI-X vectors assigned\n",
                               pci_name(dev));
@@ -929,8 +938,11 @@ void pci_disable_msi(struct pci_dev* dev)
 
        if (!pci_msi_enable)
                return;
+       if (!dev)
+               return;
 
-       if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSI)))
+       pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
+       if (!pos)
                return;
 
        pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -1104,10 +1116,12 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
        if (!pci_msi_enable || !dev || !entries)
                return -EINVAL;
 
-       if ((status = msi_init()) < 0)
+       status = msi_init();
+       if (status < 0)
                return status;
 
-       if (!(pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)))
+       pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+       if (!pos)
                return -EINVAL;
 
        pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -1188,8 +1202,11 @@ void pci_disable_msix(struct pci_dev* dev)
 
        if (!pci_msi_enable)
                return;
+       if (!dev)
+               return;
 
-       if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)))
+       pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+       if (!pos)
                return;
 
        pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -1249,8 +1266,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
                return;
 
        temp = dev->irq;                /* Save IOAPIC IRQ */
-       if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) > 0 &&
-               !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
+       pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
+       if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
                spin_lock_irqsave(&msi_lock, flags);
                state = msi_desc[dev->irq]->msi_attrib.state;
                spin_unlock_irqrestore(&msi_lock, flags);
@@ -1263,8 +1280,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
                        msi_free_vector(dev, dev->irq, 0);
                dev->irq = temp;                /* Restore IOAPIC IRQ */
        }
-       if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 &&
-               !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
+       pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+       if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
                int vector, head, tail = 0, warning = 0;
                void __iomem *base = NULL;