x86/PCI: Fix PCI IRQ routing table memory leak
authorWenwen Wang <wang6495@umn.edu>
Wed, 17 Apr 2019 14:18:50 +0000 (09:18 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 17 Apr 2019 20:27:03 +0000 (15:27 -0500)
In pcibios_irq_init(), the PCI IRQ routing table 'pirq_table' is first
found through pirq_find_routing_table().  If the table is not found and
CONFIG_PCI_BIOS is defined, the table is then allocated in
pcibios_get_irq_routing_table() using kmalloc().  Later, if the I/O APIC is
used, this table is actually not used.  In that case, the allocated table
is not freed, which is a memory leak.

Free the allocated table if it is not used.

Signed-off-by: Wenwen Wang <wang6495@umn.edu>
[bhelgaas: added Ingo's reviewed-by, since the only change since v1 was to
use the irq_routing_table local variable name he suggested]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
arch/x86/pci/irq.c

index 52e55108404ebfd9f003bde6dd08f4be98531a9f..d3a73f9335e11c3f8f285ab18ce1ae4f04b0c27f 100644 (file)
@@ -1119,6 +1119,8 @@ static const struct dmi_system_id pciirq_dmi_table[] __initconst = {
 
 void __init pcibios_irq_init(void)
 {
+       struct irq_routing_table *rtable = NULL;
+
        DBG(KERN_DEBUG "PCI: IRQ init\n");
 
        if (raw_pci_ops == NULL)
@@ -1129,8 +1131,10 @@ void __init pcibios_irq_init(void)
        pirq_table = pirq_find_routing_table();
 
 #ifdef CONFIG_PCI_BIOS
-       if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN))
+       if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) {
                pirq_table = pcibios_get_irq_routing_table();
+               rtable = pirq_table;
+       }
 #endif
        if (pirq_table) {
                pirq_peer_trick();
@@ -1145,8 +1149,10 @@ void __init pcibios_irq_init(void)
                 * If we're using the I/O APIC, avoid using the PCI IRQ
                 * routing table
                 */
-               if (io_apic_assign_pci_irqs)
+               if (io_apic_assign_pci_irqs) {
+                       kfree(rtable);
                        pirq_table = NULL;
+               }
        }
 
        x86_init.pci.fixup_irqs();