From: Alexei Starovoitov <ast@plumgrid.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Neil Horman <nhorman@tuxdriver.com>,
"David S. Miller" <davem@davemloft.net>,
linux-pci@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] pci/msi: fix memory leak in free_msi_irqs()
Date: Wed, 4 Jun 2014 15:49:50 -0700 [thread overview]
Message-ID: <1401922190-25357-1-git-send-email-ast@plumgrid.com> (raw)
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.
Fixes: 1c51b50c2995 ("PCI/MSI: Export MSI mode using attributes, not kobjects")
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
---
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/0x70
IGB 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(-)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 955ab7990c5b..fb02fc2fb034 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -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);
--
1.7.9.5
next reply other threads:[~2014-06-04 22:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-04 22:49 Alexei Starovoitov [this message]
2014-06-05 11:04 ` [PATCH] pci/msi: fix memory leak in free_msi_irqs() Neil Horman
2014-06-06 0:02 ` Greg Kroah-Hartman
2014-06-11 17:25 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1401922190-25357-1-git-send-email-ast@plumgrid.com \
--to=ast@plumgrid.com \
--cc=bhelgaas@google.com \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).