From: Catalin Marinas <catalin.marinas@arm.com>
To: Greg Kroah-Hartman <gregkh@suse.de>, Ming Lei <tom.leiming@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Possible memory leak in request_firmware()
Date: Tue, 07 Jul 2009 16:17:00 +0100 [thread overview]
Message-ID: <1246979820.9451.71.camel@pc1117.cambridge.arm.com> (raw)
Hi,
I get a couple kmemleak reports like below which I think happen on the
failure path (-ENOENT) of a request_firmware() call:
unreferenced object 0xc355fdb0 (size 256):
comm "NetworkManager", pid 2606, jiffies 4294902882
backtrace:
[<c01e0c3a>] create_object+0xfa/0x250
[<c01e1e7d>] kmemleak_alloc+0x5d/0x70
[<c01dac1b>] kmem_cache_alloc+0x14b/0x190
[<c03a0c4c>] _request_firmware+0x11c/0x530
[<c03a1102>] request_firmware+0x12/0x20
[<f95f6591>] iwl_mac_start+0xa1/0x850 [iwlagn]
[<f8fb08c1>] ieee80211_open+0x2e1/0x860 [mac80211]
[<c048459a>] dev_open+0xba/0x100
[<c0483ab9>] dev_change_flags+0x139/0x1d0
[<c048d392>] do_setlink+0x282/0x410
[<c048ea81>] rtnl_setlink+0xf1/0x130
[<c048e285>] rtnetlink_rcv_msg+0x165/0x200
[<c049fac6>] netlink_rcv_skb+0x76/0xa0
[<c048e10e>] rtnetlink_rcv+0x1e/0x30
[<c049f7fb>] netlink_unicast+0x23b/0x250
[<c04a02db>] netlink_sendmsg+0x1db/0x2d0
The f_dev in _request_firmware() is allocated via the fw_setup_device()
and fw_register_device() calls and its class set to firmware_class (the
class release function is fw_dev_release).
Commit 6acf70f078ca replaced the kfree(dev) in fw_dev_release() with a
put_device() call but my understanding is that the release function is
called via put_device -> kobject_put -> kref_put -> koject_release etc.
and it should call kfree since it's the last to see this device
structure alive.
Because of that, the _request_firmware() function on its -ENOENT error
path only calls device_unregister(f_dev) which would eventually call
fw_dev_release() but there is no kfree (the subsequent put_device call
would just make the kref negative).
The patch below may fix the problem but it's only later tonight that I
can test it and confirm:
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index ddeb819..12e6e64 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -357,7 +357,7 @@ static void fw_dev_release(struct device *dev)
kfree(fw_priv->pages);
kfree(fw_priv->fw_id);
kfree(fw_priv);
- put_device(dev);
+ kfree(dev);
module_put(THIS_MODULE);
}
@@ -407,14 +407,13 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
retval = device_register(f_dev);
if (retval) {
dev_err(device, "%s: device_register failed\n", __func__);
+ kfree(fw_priv->fw_id);
put_device(f_dev);
- goto error_kfree_fw_id;
+ return retval;
}
*dev_p = f_dev;
return 0;
-error_kfree_fw_id:
- kfree(fw_priv->fw_id);
error_kfree:
kfree(f_dev);
kfree(fw_priv);
--
Catalin
next reply other threads:[~2009-07-07 15:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-07 15:17 Catalin Marinas [this message]
2009-07-07 17:01 ` Possible memory leak in request_firmware() Cornelia Huck
2009-07-07 21:50 ` Catalin Marinas
2009-07-08 4:38 ` Ming Lei
2009-07-08 6:28 ` David Woodhouse
2009-07-08 8:42 ` Ming Lei
2009-07-08 8:56 ` David Woodhouse
2009-07-08 0:18 ` Ming Lei
2009-07-10 17:36 ` Greg KH
2009-07-10 22:49 ` Catalin Marinas
2009-07-10 22:56 ` Greg KH
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=1246979820.9451.71.camel@pc1117.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tom.leiming@gmail.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