[PATCH 5/7] MSI: add attach_msi_entry()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The attach_msi_entry(*dev, *entry) links a msi_desc *entry to
a target device *dev.  It also set entry->dev so that we can
check entry->dev to know whether the msi_desc is attached to
the proper device.

The name bit more intuitive than plain list_add_tail() will help
thinking it as a family of alloc_msi_entry() and free_msi_entries().

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
---
 drivers/pci/msi.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 4a4a138..a45fc8b 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -266,6 +266,7 @@ static void free_msi_entries(struct pci_dev *dev)
 	struct msi_desc *entry, *tmp;
 
 	list_for_each_entry(entry, &dev->msi_list, list) {
+		BUG_ON(!entry || !entry->dev || entry->dev != dev);
 		if (entry->irq)
 			BUG_ON(irq_has_action(entry->irq));
 	}
@@ -286,6 +287,12 @@ static void free_msi_entries(struct pci_dev *dev)
 	}
 }
 
+static void attach_msi_entry(struct pci_dev *dev, struct msi_desc *entry)
+{
+	entry->dev = dev;
+	list_add_tail(&entry->list, &dev->msi_list);
+}
+
 static struct msi_desc* alloc_msi_entry(void)
 {
 	struct msi_desc *entry;
@@ -398,7 +405,6 @@ static int msi_capability_init(struct pci_dev *dev)
 	entry->msi_attrib.masked = 1;
 	entry->msi_attrib.default_irq = dev->irq;	/* Save IOAPIC IRQ */
 	entry->msi_attrib.pos = pos;
-	entry->dev = dev;
 	if (entry->msi_attrib.maskbit) {
 		unsigned int base, maskbits, temp;
 
@@ -413,7 +419,7 @@ static int msi_capability_init(struct pci_dev *dev)
 		pci_write_config_dword(dev, base, maskbits);
 		entry->msi_attrib.maskbits_mask = temp;
 	}
-	list_add_tail(&entry->list, &dev->msi_list);
+	attach_msi_entry(dev, entry);
 
 	/* Configure MSI capability structure */
 	ret = arch_setup_msi_irqs(dev, 1, PCI_CAP_ID_MSI);
@@ -481,10 +487,9 @@ static int msix_capability_init(struct pci_dev *dev,
 		entry->msi_attrib.masked = 1;
 		entry->msi_attrib.default_irq = dev->irq;
 		entry->msi_attrib.pos = pos;
-		entry->dev = dev;
 		entry->mask_base = base;
 
-		list_add_tail(&entry->list, &dev->msi_list);
+		attach_msi_entry(dev, entry);
 	}
 
 	ret = arch_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
-- 
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux