Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/PCI: Fix PCI IRQ routing table memory leak

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>

authored by

Wenwen Wang and committed by
Bjorn Helgaas
ea094d53 804ee5be

+8 -2
+8 -2
arch/x86/pci/irq.c
··· 1119 1119 1120 1120 void __init pcibios_irq_init(void) 1121 1121 { 1122 + struct irq_routing_table *rtable = NULL; 1123 + 1122 1124 DBG(KERN_DEBUG "PCI: IRQ init\n"); 1123 1125 1124 1126 if (raw_pci_ops == NULL) ··· 1131 1129 pirq_table = pirq_find_routing_table(); 1132 1130 1133 1131 #ifdef CONFIG_PCI_BIOS 1134 - if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) 1132 + if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) { 1135 1133 pirq_table = pcibios_get_irq_routing_table(); 1134 + rtable = pirq_table; 1135 + } 1136 1136 #endif 1137 1137 if (pirq_table) { 1138 1138 pirq_peer_trick(); ··· 1149 1145 * If we're using the I/O APIC, avoid using the PCI IRQ 1150 1146 * routing table 1151 1147 */ 1152 - if (io_apic_assign_pci_irqs) 1148 + if (io_apic_assign_pci_irqs) { 1149 + kfree(rtable); 1153 1150 pirq_table = NULL; 1151 + } 1154 1152 } 1155 1153 1156 1154 x86_init.pci.fixup_irqs();