aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/msi.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@linux.intel.com>2009-03-17 08:54:07 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-03-20 13:48:12 -0400
commit379f5327a86f7822a51ec7d088a085167724df75 (patch)
treefb69768e7b05143d456b0c67d423018d9767be99 /drivers/pci/msi.c
parent24d27553390c69d11cdbd930d635193956fc295f (diff)
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: Matthew Wilcox <willy@linux.intel.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci/msi.c')
-rw-r--r--drivers/pci/msi.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index b3db4388f974..a658c0f34e16 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -110,7 +110,7 @@ static void msix_flush_writes(struct irq_desc *desc)
110 struct msi_desc *entry; 110 struct msi_desc *entry;
111 111
112 entry = get_irq_desc_msi(desc); 112 entry = get_irq_desc_msi(desc);
113 BUG_ON(!entry || !entry->dev); 113 BUG_ON(!entry);
114 if (entry->msi_attrib.is_msix) { 114 if (entry->msi_attrib.is_msix) {
115 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE + 115 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
116 PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET; 116 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 struct msi_desc *entry; 132 struct msi_desc *entry;
133 133
134 entry = get_irq_desc_msi(desc); 134 entry = get_irq_desc_msi(desc);
135 BUG_ON(!entry || !entry->dev); 135 BUG_ON(!entry);
136 if (entry->msi_attrib.is_msix) { 136 if (entry->msi_attrib.is_msix) {
137 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE + 137 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
138 PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET; 138 PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
@@ -248,19 +248,16 @@ void unmask_msi_irq(unsigned int irq)
248 248
249static int msi_free_irqs(struct pci_dev* dev); 249static int msi_free_irqs(struct pci_dev* dev);
250 250
251static struct msi_desc* alloc_msi_entry(void) 251static struct msi_desc *alloc_msi_entry(struct pci_dev *dev)
252{ 252{
253 struct msi_desc *entry; 253 struct msi_desc *desc = kzalloc(sizeof(*desc), GFP_KERNEL);
254 254 if (!desc)
255 entry = kzalloc(sizeof(struct msi_desc), GFP_KERNEL);
256 if (!entry)
257 return NULL; 255 return NULL;
258 256
259 INIT_LIST_HEAD(&entry->list); 257 INIT_LIST_HEAD(&desc->list);
260 entry->irq = 0; 258 desc->dev = dev;
261 entry->dev = NULL;
262 259
263 return entry; 260 return desc;
264} 261}
265 262
266static void pci_intx_for_msi(struct pci_dev *dev, int enable) 263static 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 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 348 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
352 pci_read_config_word(dev, msi_control_reg(pos), &control); 349 pci_read_config_word(dev, msi_control_reg(pos), &control);
353 /* MSI Entry Initialization */ 350 /* MSI Entry Initialization */
354 entry = alloc_msi_entry(); 351 entry = alloc_msi_entry(dev);
355 if (!entry) 352 if (!entry)
356 return -ENOMEM; 353 return -ENOMEM;
357 354
@@ -362,7 +359,6 @@ static int msi_capability_init(struct pci_dev *dev)
362 entry->msi_attrib.masked = 1; 359 entry->msi_attrib.masked = 1;
363 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ 360 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
364 entry->msi_attrib.pos = pos; 361 entry->msi_attrib.pos = pos;
365 entry->dev = dev;
366 if (entry->msi_attrib.maskbit) { 362 if (entry->msi_attrib.maskbit) {
367 unsigned int base, maskbits, temp; 363 unsigned int base, maskbits, temp;
368 364
@@ -432,7 +428,7 @@ static int msix_capability_init(struct pci_dev *dev,
432 428
433 /* MSI-X Table Initialization */ 429 /* MSI-X Table Initialization */
434 for (i = 0; i < nvec; i++) { 430 for (i = 0; i < nvec; i++) {
435 entry = alloc_msi_entry(); 431 entry = alloc_msi_entry(dev);
436 if (!entry) 432 if (!entry)
437 break; 433 break;
438 434
@@ -444,7 +440,6 @@ static int msix_capability_init(struct pci_dev *dev,
444 entry->msi_attrib.masked = 1; 440 entry->msi_attrib.masked = 1;
445 entry->msi_attrib.default_irq = dev->irq; 441 entry->msi_attrib.default_irq = dev->irq;
446 entry->msi_attrib.pos = pos; 442 entry->msi_attrib.pos = pos;
447 entry->dev = dev;
448 entry->mask_base = base; 443 entry->mask_base = base;
449 444
450 list_add_tail(&entry->list, &dev->msi_list); 445 list_add_tail(&entry->list, &dev->msi_list);
@@ -581,7 +576,7 @@ void pci_msi_shutdown(struct pci_dev* dev)
581 struct irq_desc *desc = irq_to_desc(dev->irq); 576 struct irq_desc *desc = irq_to_desc(dev->irq);
582 msi_set_mask_bits(desc, mask, ~mask); 577 msi_set_mask_bits(desc, mask, ~mask);
583 } 578 }
584 if (!entry->dev || entry->msi_attrib.is_msix) 579 if (entry->msi_attrib.is_msix)
585 return; 580 return;
586 581
587 /* Restore dev->irq to its default pin-assertion irq */ 582 /* Restore dev->irq to its default pin-assertion irq */
@@ -598,7 +593,7 @@ void pci_disable_msi(struct pci_dev* dev)
598 pci_msi_shutdown(dev); 593 pci_msi_shutdown(dev);
599 594
600 entry = list_entry(dev->msi_list.next, struct msi_desc, list); 595 entry = list_entry(dev->msi_list.next, struct msi_desc, list);
601 if (!entry->dev || entry->msi_attrib.is_msix) 596 if (entry->msi_attrib.is_msix)
602 return; 597 return;
603 598
604 msi_free_irqs(dev); 599 msi_free_irqs(dev);