Re: [PATCH 086/190] Revert "x86/PCI: Fix PCI IRQ routing table memory leak"

From: Thomas Gleixner
Date: Fri Apr 23 2021 - 05:53:44 EST


On Thu, Apr 22 2021 at 00:09, Bjorn Helgaas wrote:
> On Wed, Apr 21, 2021 at 02:59:21PM +0200, Greg Kroah-Hartman wrote:
> I would prefer that you not apply this revert.
>
> Prior to ea094d53580f ("x86/PCI: Fix PCI IRQ routing table memory
> leak"), we had essentially this:
>
> pcibios_irq_init()
> pirq_table = pcibios_get_irq_routing_table(); # kmallocs
> if (pirq_table) {
> if (io_apic_assign_pci_irqs)
> pirq_table = NULL;
> }
>
> So if we called pcibios_get_irq_routing_table(), we kmalloced some
> space and then (if io_apic_assign_pci_irqs) threw away the pointer,
> which leaks the pointer as the commit log says.
>
> After ea094d53580f, we have:
>
> pcibios_irq_init()
> rtable = NULL;
> pirq_table = pcibios_get_irq_routing_table(); # kmallocs
> rtable = pirq_table;
> if (pirq_table) {
> if (io_apic_assign_pci_irqs) {
> kfree(rtable);
> pirq_table = NULL;
> }
> }
>
> which seems right to me.

It is correct.

Though looking at it again, the question is why this invokes
pcibios_get_irq_routing_table() at all if io_apic_assign_pci_irqs is
true?

Thanks,

tglx