PCI MSI: Return if alloc_msi_entry for MSI-X failed
authorHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Wed, 24 Jun 2009 03:08:27 +0000 (12:08 +0900)
committerJesse Barnes <jbarnes@virtuousgeek.org>
Mon, 29 Jun 2009 19:10:10 +0000 (12:10 -0700)
In current code it continues setup even if alloc_msi_entry() for MSI-X
is failed due to lack of memory.  It means arch_setup_msi_irqs() might
be called with msi_desc entries less than its argument nvec.

At least x86's arch_setup_msi_irqs() uses list_for_each_entry() for
dev->msi_list that suspected to have entries same numbers as nvec, and
it doesn't check the number of allocated vectors and passed arg nvec.
Therefore it will result in success of pci_enable_msix(), with less
vectors allocated than requested.

This patch fixes the error route to return -ENOMEM, instead of continuing
the setup (proposed by Matthew Wilcox).

Note that there is no iounmap in msi_free_irqs() if no msi_disc is
allocated.

Reviewed-by: Matthew Wilcox <matthew@wil.cx>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
drivers/pci/msi.c

index d9f06fb..628c141 100644 (file)
@@ -439,8 +439,14 @@ static int msix_capability_init(struct pci_dev *dev,
 
        for (i = 0; i < nvec; i++) {
                entry = alloc_msi_entry(dev);
-               if (!entry)
-                       break;
+               if (!entry) {
+                       if (!i)
+                               iounmap(base);
+                       else
+                               msi_free_irqs(dev);
+                       /* No enough memory. Don't try again */
+                       return -ENOMEM;
+               }
 
                j = entries[i].entry;
                entry->msi_attrib.is_msix = 1;