pci/msi: fix memory leak in free_msi_irqs()
Subsystems (3)
PATCH 1/1 pci/msi: fix memory leak in free_msi_irqs()
free_msi_irqs() is leaking memory, since list_for_each_entry(entry, &dev->msi_list, list) {...} is never executed, because dev->msi_list is made empty by the loop just above this one.
Fix it by relying on zero termination of attribute array like populate_msi_sysfs() does.
---
This was found by kmemleak report:
unreferenced object 0xffff880808eda600 (size 64):
comm "modprobe", pid 1526, jiffies 4294902299 (age 58422.716s) hex dump (first 32 bytes):
20 c4 66 09 08 88 ff ff 24 01 00 00 00 00 00 00 .f.....$.......
50 97 77 82 ff ff ff ff 00 00 00 00 00 00 00 00 P.w.............
backtrace:
[<ffffffff816e5fc8>] kmemleak_alloc+0x28/0x50
[<ffffffff811b885e>] kmem_cache_alloc_trace+0xde/0x230
[<ffffffff813aa286>] populate_msi_sysfs+0xc6/0x250
[<ffffffff813aafdb>] pci_enable_msix+0x34b/0x430
[<ffffffff813ab0ec>] pci_enable_msix_range+0x2c/0x70
[<ffffffffa0034ade>] igb_init_interrupt_scheme+0x9e/0x420 [igb]
[<ffffffffa003d668>] igb_probe+0x4a8/0x1250 [igb]
[<ffffffff813930de>] local_pci_probe+0x4e/0xa0
[<ffffffff813933e9>] pci_device_probe+0xd9/0x120
[<ffffffff814697cd>] driver_probe_device+0x8d/0x250
[<ffffffff81469a3b>] __driver_attach+0xab/0xb0
[<ffffffff8146799d>] bus_for_each_dev+0x5d/0xa0
[<ffffffff814691de>] driver_attach+0x1e/0x20
[<ffffffff81468e57>] bus_add_driver+0x117/0x220
[<ffffffff8146a104>] driver_register+0x64/0xf0
[<ffffffff813923f4>] __pci_register_driver+0x64/0x70IGB driver is calling pci_enable_msix_range() and immediately pci_disable_msix() which leaks the memory.
Obviously the leak happens with any driver.
drivers/pci/msi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/msi.c +1 -1
@@ -414,7 +414,7 @@ static void free_msi_irqs(struct pci_dev *dev)if (dev->msi_irq_groups) {sysfs_remove_groups (&dev->dev.kobj, dev->msi_irq_groups); msi_attrs = dev->msi_irq_groups[0 ]->attrs; -list_for_each_entry (entry, &dev->msi_list, list) { +while (msi_attrs[count]) { dev_attr =container_of (msi_attrs[count], struct device_attribute, attr);kfree (dev_attr->attr.name);
Signature · 1 line
1.7.9.5
Quoted 60 lines · Alexei Starovoitov
free_msi_irqs()is leaking memory, sincelist_for_each_entry(entry, &dev->msi_list, list){...} is never executed, becausedev->msi_listis made empty by the loop just above this one.Fix it by relying on zero termination of attribute array like
populate_msi_sysfs()does.Fixes 1c51b50c2995 ("PCI/MSI: Export MSI mode using attributes, not kobjects")Signed-off-by Alexei Starovoitov <[email protected]>---
This was found by kmemleak report:
unreferenced object0xffff880808eda600(size 64):
comm "modprobe", pid 1526, jiffies 4294902299 (age 58422.716s) hex dump (first 32 bytes):20 c4 66 09 08 88 ff ff 24 01 00 00 00 00 00 00 .f.....$....... 50 97 77 82 ff ff ff ff 00 00 00 00 00 00 00 00 P.w............. backtrace: [<ffffffff816e5fc8>] kmemleak_alloc+0x28/0x50 [<ffffffff811b885e>] kmem_cache_alloc_trace+0xde/0x230 [<ffffffff813aa286>] populate_msi_sysfs+0xc6/0x250 [<ffffffff813aafdb>] pci_enable_msix+0x34b/0x430 [<ffffffff813ab0ec>] pci_enable_msix_range+0x2c/0x70 [<ffffffffa0034ade>] igb_init_interrupt_scheme+0x9e/0x420 [igb] [<ffffffffa003d668>] igb_probe+0x4a8/0x1250 [igb] [<ffffffff813930de>] local_pci_probe+0x4e/0xa0 [<ffffffff813933e9>] pci_device_probe+0xd9/0x120 [<ffffffff814697cd>] driver_probe_device+0x8d/0x250 [<ffffffff81469a3b>] __driver_attach+0xab/0xb0 [<ffffffff8146799d>] bus_for_each_dev+0x5d/0xa0 [<ffffffff814691de>] driver_attach+0x1e/0x20 [<ffffffff81468e57>] bus_add_driver+0x117/0x220 [<ffffffff8146a104>] driver_register+0x64/0xf0 [<ffffffff813923f4>] __pci_register_driver+0x64/0x70IGB driver is calling
pci_enable_msix_range()and immediatelypci_disable_msix()which leaks the memory.
Obviously the leak happens with any driver.drivers/pci/msi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/msi.c +1
-1@@ -414,7 +414,7 @@ static void free_msi_irqs(struct pci_dev *dev)if (dev->msi_irq_groups) {sysfs_remove_groups (&dev->dev.kobj, dev->msi_irq_groups); msi_attrs = dev->msi_irq_groups[0 ]->attrs; -list_for_each_entry (entry, &dev->msi_list, list) { +while (msi_attrs[count]) { dev_attr =container_of (msi_attrs[count], struct device_attribute, attr);kfree (dev_attr->attr.name);Signature · 1 line
1.7.9.5
Quoted 48 lines · Alexei Starovoitov
free_msi_irqs()is leaking memory, sincelist_for_each_entry(entry, &dev->msi_list, list){...} is never executed, becausedev->msi_listis made empty by the loop just above this one.Fix it by relying on zero termination of attribute array like
populate_msi_sysfs()does.Fixes 1c51b50c2995 ("PCI/MSI: Export MSI mode using attributes, not kobjects")Signed-off-by Alexei Starovoitov <[email protected]>---
This was found by kmemleak report:
unreferenced object0xffff880808eda600(size 64):
comm "modprobe", pid 1526, jiffies 4294902299 (age 58422.716s) hex dump (first 32 bytes):20 c4 66 09 08 88 ff ff 24 01 00 00 00 00 00 00 .f.....$....... 50 97 77 82 ff ff ff ff 00 00 00 00 00 00 00 00 P.w............. backtrace: [<ffffffff816e5fc8>] kmemleak_alloc+0x28/0x50 [<ffffffff811b885e>] kmem_cache_alloc_trace+0xde/0x230 [<ffffffff813aa286>] populate_msi_sysfs+0xc6/0x250 [<ffffffff813aafdb>] pci_enable_msix+0x34b/0x430 [<ffffffff813ab0ec>] pci_enable_msix_range+0x2c/0x70 [<ffffffffa0034ade>] igb_init_interrupt_scheme+0x9e/0x420 [igb] [<ffffffffa003d668>] igb_probe+0x4a8/0x1250 [igb] [<ffffffff813930de>] local_pci_probe+0x4e/0xa0 [<ffffffff813933e9>] pci_device_probe+0xd9/0x120 [<ffffffff814697cd>] driver_probe_device+0x8d/0x250 [<ffffffff81469a3b>] __driver_attach+0xab/0xb0 [<ffffffff8146799d>] bus_for_each_dev+0x5d/0xa0 [<ffffffff814691de>] driver_attach+0x1e/0x20 [<ffffffff81468e57>] bus_add_driver+0x117/0x220 [<ffffffff8146a104>] driver_register+0x64/0xf0 [<ffffffff813923f4>] __pci_register_driver+0x64/0x70IGB driver is calling
pci_enable_msix_range()and immediatelypci_disable_msix()which leaks the memory.
Obviously the leak happens with any driver.drivers/pci/msi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/msi.c +0
-0
drivers/pci/msi.c static void free_msi_irqs(struct pci_dev *dev) · line 420
Quoted 8 lines
drivers/pci/msi.c +1
-1@@ -414,7 +414,7 @@ static void free_msi_irqs(struct pci_dev *dev)if (dev->msi_irq_groups) {sysfs_remove_groups (&dev->dev.kobj, dev->msi_irq_groups); msi_attrs = dev->msi_irq_groups[0 ]->attrs; -list_for_each_entry (entry, &dev->msi_list, list) { +while (msi_attrs[count]) { dev_attr =container_of (msi_attrs[count], struct device_attribute, attr);kfree (dev_attr->attr.name);
Looks good, thanks for catching this:
Bjorn Helgaas
maintainerQuoted 10 lines · Alexei Starovoitov
free_msi_irqs()is leaking memory, sincelist_for_each_entry(entry, &dev->msi_list, list){...} is never executed, becausedev->msi_listis made empty by the loop just above this one.Fix it by relying on zero termination of attribute array like
populate_msi_sysfs()does.Fixes 1c51b50c2995 ("PCI/MSI: Export MSI mode using attributes, not kobjects")Signed-off-by Alexei Starovoitov <[email protected]>
I added Neil and Greg's acks and a stable tag and will merge this for v3.16. Thanks!
Quoted 49 lines
---
This was found by kmemleak report:
unreferenced object0xffff880808eda600(size 64):
comm "modprobe", pid 1526, jiffies 4294902299 (age 58422.716s) hex dump (first 32 bytes):20 c4 66 09 08 88 ff ff 24 01 00 00 00 00 00 00 .f.....$....... 50 97 77 82 ff ff ff ff 00 00 00 00 00 00 00 00 P.w............. backtrace: [<ffffffff816e5fc8>] kmemleak_alloc+0x28/0x50 [<ffffffff811b885e>] kmem_cache_alloc_trace+0xde/0x230 [<ffffffff813aa286>] populate_msi_sysfs+0xc6/0x250 [<ffffffff813aafdb>] pci_enable_msix+0x34b/0x430 [<ffffffff813ab0ec>] pci_enable_msix_range+0x2c/0x70 [<ffffffffa0034ade>] igb_init_interrupt_scheme+0x9e/0x420 [igb] [<ffffffffa003d668>] igb_probe+0x4a8/0x1250 [igb] [<ffffffff813930de>] local_pci_probe+0x4e/0xa0 [<ffffffff813933e9>] pci_device_probe+0xd9/0x120 [<ffffffff814697cd>] driver_probe_device+0x8d/0x250 [<ffffffff81469a3b>] __driver_attach+0xab/0xb0 [<ffffffff8146799d>] bus_for_each_dev+0x5d/0xa0 [<ffffffff814691de>] driver_attach+0x1e/0x20 [<ffffffff81468e57>] bus_add_driver+0x117/0x220 [<ffffffff8146a104>] driver_register+0x64/0xf0 [<ffffffff813923f4>] __pci_register_driver+0x64/0x70IGB driver is calling
pci_enable_msix_range()and immediatelypci_disable_msix()which leaks the memory.
Obviously the leak happens with any driver.drivers/pci/msi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/msi.c +1
-1@@ -414,7 +414,7 @@ static void free_msi_irqs(struct pci_dev *dev)if (dev->msi_irq_groups) {sysfs_remove_groups (&dev->dev.kobj, dev->msi_irq_groups); msi_attrs = dev->msi_irq_groups[0 ]->attrs; -list_for_each_entry (entry, &dev->msi_list, list) { +while (msi_attrs[count]) { dev_attr =container_of (msi_attrs[count], struct device_attribute, attr);kfree (dev_attr->attr.name);Signature · 1 line
1.7.9.5