Commit 379f5327 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Jesse Barnes

PCI MSI: msi_desc->dev is always initialised

By passing the pci_dev into alloc_msi_entry() we can be sure that
the ->dev entry is always assigned and so we don't need to check it.
Also, we used kzalloc() so we don't need to initialise ->irq to 0.
Signed-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 24d27553
...@@ -110,7 +110,7 @@ static void msix_flush_writes(struct irq_desc *desc) ...@@ -110,7 +110,7 @@ static void msix_flush_writes(struct irq_desc *desc)
struct msi_desc *entry; struct msi_desc *entry;
entry = get_irq_desc_msi(desc); entry = get_irq_desc_msi(desc);
BUG_ON(!entry || !entry->dev); BUG_ON(!entry);
if (entry->msi_attrib.is_msix) { if (entry->msi_attrib.is_msix) {
int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE + int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET; PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
...@@ -132,7 +132,7 @@ static int msi_set_mask_bits(struct irq_desc *desc, u32 mask, u32 flag) ...@@ -132,7 +132,7 @@ static int msi_set_mask_bits(struct irq_desc *desc, u32 mask, u32 flag)
struct msi_desc *entry; struct msi_desc *entry;
entry = get_irq_desc_msi(desc); entry = get_irq_desc_msi(desc);
BUG_ON(!entry || !entry->dev); BUG_ON(!entry);
if (entry->msi_attrib.is_msix) { if (entry->msi_attrib.is_msix) {
int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE + int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET; PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
...@@ -248,19 +248,16 @@ void unmask_msi_irq(unsigned int irq) ...@@ -248,19 +248,16 @@ void unmask_msi_irq(unsigned int irq)
static int msi_free_irqs(struct pci_dev* dev); static int msi_free_irqs(struct pci_dev* dev);
static struct msi_desc* alloc_msi_entry(void) static struct msi_desc *alloc_msi_entry(struct pci_dev *dev)
{ {
struct msi_desc *entry; struct msi_desc *desc = kzalloc(sizeof(*desc), GFP_KERNEL);
if (!desc)
entry = kzalloc(sizeof(struct msi_desc), GFP_KERNEL);
if (!entry)
return NULL; return NULL;
INIT_LIST_HEAD(&entry->list); INIT_LIST_HEAD(&desc->list);
entry->irq = 0; desc->dev = dev;
entry->dev = NULL;
return entry; return desc;
} }
static void pci_intx_for_msi(struct pci_dev *dev, int enable) static void pci_intx_for_msi(struct pci_dev *dev, int enable)
...@@ -351,7 +348,7 @@ static int msi_capability_init(struct pci_dev *dev) ...@@ -351,7 +348,7 @@ 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 */
entry = alloc_msi_entry(); entry = alloc_msi_entry(dev);
if (!entry) if (!entry)
return -ENOMEM; return -ENOMEM;
...@@ -362,7 +359,6 @@ static int msi_capability_init(struct pci_dev *dev) ...@@ -362,7 +359,6 @@ static int msi_capability_init(struct pci_dev *dev)
entry->msi_attrib.masked = 1; entry->msi_attrib.masked = 1;
entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
entry->msi_attrib.pos = pos; entry->msi_attrib.pos = pos;
entry->dev = dev;
if (entry->msi_attrib.maskbit) { if (entry->msi_attrib.maskbit) {
unsigned int base, maskbits, temp; unsigned int base, maskbits, temp;
...@@ -432,7 +428,7 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -432,7 +428,7 @@ static int msix_capability_init(struct pci_dev *dev,
/* MSI-X Table Initialization */ /* MSI-X Table Initialization */
for (i = 0; i < nvec; i++) { for (i = 0; i < nvec; i++) {
entry = alloc_msi_entry(); entry = alloc_msi_entry(dev);
if (!entry) if (!entry)
break; break;
...@@ -444,7 +440,6 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -444,7 +440,6 @@ static int msix_capability_init(struct pci_dev *dev,
entry->msi_attrib.masked = 1; entry->msi_attrib.masked = 1;
entry->msi_attrib.default_irq = dev->irq; entry->msi_attrib.default_irq = dev->irq;
entry->msi_attrib.pos = pos; entry->msi_attrib.pos = pos;
entry->dev = dev;
entry->mask_base = base; entry->mask_base = base;
list_add_tail(&entry->list, &dev->msi_list); list_add_tail(&entry->list, &dev->msi_list);
...@@ -581,7 +576,7 @@ void pci_msi_shutdown(struct pci_dev* dev) ...@@ -581,7 +576,7 @@ void pci_msi_shutdown(struct pci_dev* dev)
struct irq_desc *desc = irq_to_desc(dev->irq); struct irq_desc *desc = irq_to_desc(dev->irq);
msi_set_mask_bits(desc, mask, ~mask); msi_set_mask_bits(desc, mask, ~mask);
} }
if (!entry->dev || entry->msi_attrib.is_msix) if (entry->msi_attrib.is_msix)
return; return;
/* Restore dev->irq to its default pin-assertion irq */ /* Restore dev->irq to its default pin-assertion irq */
...@@ -598,7 +593,7 @@ void pci_disable_msi(struct pci_dev* dev) ...@@ -598,7 +593,7 @@ void pci_disable_msi(struct pci_dev* dev)
pci_msi_shutdown(dev); pci_msi_shutdown(dev);
entry = list_entry(dev->msi_list.next, struct msi_desc, list); entry = list_entry(dev->msi_list.next, struct msi_desc, list);
if (!entry->dev || entry->msi_attrib.is_msix) if (entry->msi_attrib.is_msix)
return; return;
msi_free_irqs(dev); msi_free_irqs(dev);
......
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