Skip to content

Commit 379f532

Browse files
Matthew Wilcoxjbarnes993
authored andcommitted
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 <[email protected]> Signed-off-by: Jesse Barnes <[email protected]>
1 parent 24d2755 commit 379f532

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

drivers/pci/msi.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void msix_flush_writes(struct irq_desc *desc)
110110
struct msi_desc *entry;
111111

112112
entry = get_irq_desc_msi(desc);
113-
BUG_ON(!entry || !entry->dev);
113+
BUG_ON(!entry);
114114
if (entry->msi_attrib.is_msix) {
115115
int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
116116
PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
@@ -132,7 +132,7 @@ static int msi_set_mask_bits(struct irq_desc *desc, u32 mask, u32 flag)
132132
struct msi_desc *entry;
133133

134134
entry = get_irq_desc_msi(desc);
135-
BUG_ON(!entry || !entry->dev);
135+
BUG_ON(!entry);
136136
if (entry->msi_attrib.is_msix) {
137137
int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
138138
PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
@@ -248,19 +248,16 @@ void unmask_msi_irq(unsigned int irq)
248248

249249
static int msi_free_irqs(struct pci_dev* dev);
250250

251-
static struct msi_desc* alloc_msi_entry(void)
251+
static struct msi_desc *alloc_msi_entry(struct pci_dev *dev)
252252
{
253-
struct msi_desc *entry;
254-
255-
entry = kzalloc(sizeof(struct msi_desc), GFP_KERNEL);
256-
if (!entry)
253+
struct msi_desc *desc = kzalloc(sizeof(*desc), GFP_KERNEL);
254+
if (!desc)
257255
return NULL;
258256

259-
INIT_LIST_HEAD(&entry->list);
260-
entry->irq = 0;
261-
entry->dev = NULL;
257+
INIT_LIST_HEAD(&desc->list);
258+
desc->dev = dev;
262259

263-
return entry;
260+
return desc;
264261
}
265262

266263
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)
351348
pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
352349
pci_read_config_word(dev, msi_control_reg(pos), &control);
353350
/* MSI Entry Initialization */
354-
entry = alloc_msi_entry();
351+
entry = alloc_msi_entry(dev);
355352
if (!entry)
356353
return -ENOMEM;
357354

@@ -362,7 +359,6 @@ static int msi_capability_init(struct pci_dev *dev)
362359
entry->msi_attrib.masked = 1;
363360
entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
364361
entry->msi_attrib.pos = pos;
365-
entry->dev = dev;
366362
if (entry->msi_attrib.maskbit) {
367363
unsigned int base, maskbits, temp;
368364

@@ -432,7 +428,7 @@ static int msix_capability_init(struct pci_dev *dev,
432428

433429
/* MSI-X Table Initialization */
434430
for (i = 0; i < nvec; i++) {
435-
entry = alloc_msi_entry();
431+
entry = alloc_msi_entry(dev);
436432
if (!entry)
437433
break;
438434

@@ -444,7 +440,6 @@ static int msix_capability_init(struct pci_dev *dev,
444440
entry->msi_attrib.masked = 1;
445441
entry->msi_attrib.default_irq = dev->irq;
446442
entry->msi_attrib.pos = pos;
447-
entry->dev = dev;
448443
entry->mask_base = base;
449444

450445
list_add_tail(&entry->list, &dev->msi_list);
@@ -581,7 +576,7 @@ void pci_msi_shutdown(struct pci_dev* dev)
581576
struct irq_desc *desc = irq_to_desc(dev->irq);
582577
msi_set_mask_bits(desc, mask, ~mask);
583578
}
584-
if (!entry->dev || entry->msi_attrib.is_msix)
579+
if (entry->msi_attrib.is_msix)
585580
return;
586581

587582
/* Restore dev->irq to its default pin-assertion irq */
@@ -598,7 +593,7 @@ void pci_disable_msi(struct pci_dev* dev)
598593
pci_msi_shutdown(dev);
599594

600595
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)
602597
return;
603598

604599
msi_free_irqs(dev);

0 commit comments

Comments
 (0)