Commit b64c05e7 authored by Grant Grundler's avatar Grant Grundler Committed by Greg Kroah-Hartman

[PATCH] PCI: clean up msi.c a bit

Clean up: move assignments outside of if() statements.
AFAICT, no functional change. Easier to read/understand.

Depends on "[PATCH 1/3] msi vector targeting abstractions"
by Mark Maule <maule@sgi.com>.
I expect one hunk to fail if applied against 2.6.15.

This is essentially Joe Perches' patch.
I've cleaned up the one instance added by Mark's patch.
Signed-off-by: default avatarGrant Grundler <grundler@parisc-linux.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b0e6e962
...@@ -103,9 +103,9 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask) ...@@ -103,9 +103,9 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
switch (entry->msi_attrib.type) { switch (entry->msi_attrib.type) {
case PCI_CAP_ID_MSI: 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; return;
pci_read_config_dword(entry->dev, msi_lower_address_reg(pos), pci_read_config_dword(entry->dev, msi_lower_address_reg(pos),
...@@ -347,9 +347,9 @@ static int assign_msi_vector(void) ...@@ -347,9 +347,9 @@ static int assign_msi_vector(void)
static int get_new_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]); set_intr_gate(vector, interrupt[vector]);
return vector; return vector;
...@@ -369,7 +369,8 @@ static int msi_init(void) ...@@ -369,7 +369,8 @@ static int msi_init(void)
return status; return status;
} }
if ((status = msi_cache_init()) < 0) { status = msi_cache_init();
if (status < 0) {
pci_msi_enable = 0; pci_msi_enable = 0;
printk(KERN_WARNING "PCI: MSI cache init failed\n"); printk(KERN_WARNING "PCI: MSI cache init failed\n");
return status; return status;
...@@ -523,10 +524,12 @@ static int msi_capability_init(struct pci_dev *dev) ...@@ -523,10 +524,12 @@ static int msi_capability_init(struct pci_dev *dev)
pos = pci_find_capability(dev, PCI_CAP_ID_MSI); pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
pci_read_config_word(dev, msi_control_reg(pos), &control); pci_read_config_word(dev, msi_control_reg(pos), &control);
/* MSI Entry Initialization */ /* MSI Entry Initialization */
if (!(entry = alloc_msi_entry())) entry = alloc_msi_entry();
if (!entry)
return -ENOMEM; return -ENOMEM;
if ((vector = get_msi_vector(dev)) < 0) { vector = get_msi_vector(dev);
if (vector < 0) {
kmem_cache_free(msi_cachep, entry); kmem_cache_free(msi_cachep, entry);
return -EBUSY; return -EBUSY;
} }
...@@ -620,7 +623,8 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -620,7 +623,8 @@ static int msix_capability_init(struct pci_dev *dev,
entry = alloc_msi_entry(); entry = alloc_msi_entry();
if (!entry) if (!entry)
break; break;
if ((vector = get_msi_vector(dev)) < 0) vector = get_msi_vector(dev);
if (vector < 0)
break; break;
j = entries[i].entry; j = entries[i].entry;
...@@ -701,10 +705,12 @@ int pci_enable_msi(struct pci_dev* dev) ...@@ -701,10 +705,12 @@ int pci_enable_msi(struct pci_dev* dev)
temp = dev->irq; temp = dev->irq;
if ((status = msi_init()) < 0) status = msi_init();
if (status < 0)
return status; 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; return -EINVAL;
pci_read_config_word(dev, msi_control_reg(pos), &control); pci_read_config_word(dev, msi_control_reg(pos), &control);
...@@ -728,8 +734,8 @@ int pci_enable_msi(struct pci_dev* dev) ...@@ -728,8 +734,8 @@ int pci_enable_msi(struct pci_dev* dev)
dev->irq = temp; dev->irq = temp;
} }
/* Check whether driver already requested for MSI-X vectors */ /* Check whether driver already requested for MSI-X vectors */
if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 && pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
!msi_lookup_vector(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. " printk(KERN_INFO "PCI: %s: Can't enable MSI. "
"Device already has MSI-X vectors assigned\n", "Device already has MSI-X vectors assigned\n",
pci_name(dev)); pci_name(dev));
...@@ -755,7 +761,10 @@ void pci_disable_msi(struct pci_dev* dev) ...@@ -755,7 +761,10 @@ void pci_disable_msi(struct pci_dev* dev)
u16 control; u16 control;
unsigned long flags; unsigned long flags;
if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSI))) if (!dev)
return;
pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
if (!pos)
return; return;
pci_read_config_word(dev, msi_control_reg(pos), &control); pci_read_config_word(dev, msi_control_reg(pos), &control);
...@@ -924,10 +933,12 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) ...@@ -924,10 +933,12 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
if (!pci_msi_enable || !dev || !entries) if (!pci_msi_enable || !dev || !entries)
return -EINVAL; return -EINVAL;
if ((status = msi_init()) < 0) status = msi_init();
if (status < 0)
return status; 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; return -EINVAL;
pci_read_config_word(dev, msi_control_reg(pos), &control); pci_read_config_word(dev, msi_control_reg(pos), &control);
...@@ -1006,7 +1017,11 @@ void pci_disable_msix(struct pci_dev* dev) ...@@ -1006,7 +1017,11 @@ void pci_disable_msix(struct pci_dev* dev)
int pos, temp; int pos, temp;
u16 control; u16 control;
if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSIX))) if (!dev)
return;
pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
if (!pos)
return; return;
pci_read_config_word(dev, msi_control_reg(pos), &control); pci_read_config_word(dev, msi_control_reg(pos), &control);
...@@ -1066,8 +1081,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev) ...@@ -1066,8 +1081,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
return; return;
temp = dev->irq; /* Save IOAPIC IRQ */ temp = dev->irq; /* Save IOAPIC IRQ */
if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) > 0 && pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
!msi_lookup_vector(dev, PCI_CAP_ID_MSI)) { if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
spin_lock_irqsave(&msi_lock, flags); spin_lock_irqsave(&msi_lock, flags);
state = msi_desc[dev->irq]->msi_attrib.state; state = msi_desc[dev->irq]->msi_attrib.state;
spin_unlock_irqrestore(&msi_lock, flags); spin_unlock_irqrestore(&msi_lock, flags);
...@@ -1080,8 +1095,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev) ...@@ -1080,8 +1095,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
msi_free_vector(dev, dev->irq, 0); msi_free_vector(dev, dev->irq, 0);
dev->irq = temp; /* Restore IOAPIC IRQ */ dev->irq = temp; /* Restore IOAPIC IRQ */
} }
if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 && pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
!msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) { if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
int vector, head, tail = 0, warning = 0; int vector, head, tail = 0, warning = 0;
void __iomem *base = NULL; void __iomem *base = NULL;
......
...@@ -495,9 +495,8 @@ pci_enable_device_bars(struct pci_dev *dev, int bars) ...@@ -495,9 +495,8 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
int int
pci_enable_device(struct pci_dev *dev) pci_enable_device(struct pci_dev *dev)
{ {
int err; int err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
if (err)
if ((err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1)))
return err; return err;
pci_fixup_device(pci_fixup_enable, dev); pci_fixup_device(pci_fixup_enable, dev);
dev->is_enabled = 1; dev->is_enabled = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment