From: Petr Malat <oss@malat.biz>
To: netdev@vger.kernel.org
Cc: oss@malat.biz
Subject: [PATCH]: fix phy_device_free memory leak
Date: Thu, 7 Feb 2013 00:07:57 +0100 [thread overview]
Message-ID: <201302070007.57434.oss@malat.biz> (raw)
Hi,
there is a memory leak in phy_device handling:
phy_device_create() sets name of kobject using dev_set_name(), which allocates
memory using kvasprintf(), but this memory isn't freed if the underlying
device isn't registered properly, because kobject_cleanup() is not called in
that case. This can happen (and actually is happening on our machines) if
phy_device_register(), called by mdiobus_scan(), fails. I fixed this by the
attached patch, so far it's working fine.
Patch description:
Name is freed by phy_device_free(). In the case a device is released trough
kobject_cleanup()->device_release()->phy_device_release(), the name is set to
NULL and it is not freed by phy_device_free(), because it will be freed later
by kobject_cleanup().
Please put me on CC, I'm not signed into the mailing list.
Petr
--- a/drivers/net/phy/phy_device.c 2013-02-06 19:44:11.000000000 +0100
+++ b/drivers/net/phy/phy_device.c 2013-02-06 20:56:57.000000000 +0100
@@ -41,12 +41,16 @@ MODULE_LICENSE("GPL");
void phy_device_free(struct phy_device *phydev)
{
+ kfree(phydev->dev.kobj.name);
kfree(phydev);
}
EXPORT_SYMBOL(phy_device_free);
static void phy_device_release(struct device *dev)
{
+ /* Name will be freed by kobject_cleanup() */
+ dev->kobj.name = NULL;
+
phy_device_free(to_phy_device(dev));
}
next reply other threads:[~2013-02-06 23:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-06 23:07 Petr Malat [this message]
2013-02-08 4:35 ` [PATCH]: fix phy_device_free memory leak David Miller
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=201302070007.57434.oss@malat.biz \
--to=oss@malat.biz \
--cc=netdev@vger.kernel.org \
/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