From: David Miller <davem@davemloft.net>
To: oss@malat.biz
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] phy: fix phy_device_free memory leak
Date: Tue, 19 Feb 2013 22:48:36 -0500 (EST) [thread overview]
Message-ID: <20130219.224836.2280761384227580667.davem@davemloft.net> (raw)
In-Reply-To: <20130219193646.GA10851@bordel.klfree.net>
From: Petr Malat <oss@malat.biz>
Date: Tue, 19 Feb 2013 20:36:46 +0100
> From: Petr Malat <oss@malat.biz>
>
> Fix memory leak in phy_device_free() for the case when phy_device*
> returned by phy_device_create() is not registered in the system.
>
> Bug description:
> 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.
>
> 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().
>
> Signed-off-by: Petr Malat <oss@malat.biz>
> ---
> Please put me on CC, I'm not signed into the mailing list.
I think it's cleaner to have phy_device_register() use the kobject
reference count properly.
Have it first go:
device_initialize(&phydev->dev);
And change the device_register() to device_add().
Finally, on the failure paths, do a put_device().
No funny NULL pointer assignments and state to maintainer, just using
kobject reference counting to handle it all transparently.
next prev parent reply other threads:[~2013-02-20 3:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-19 19:36 [PATCH] phy: fix phy_device_free memory leak Petr Malat
2013-02-20 3:48 ` David Miller [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-02-11 11:28 Petr Malat
2013-02-11 18:57 ` 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=20130219.224836.2280761384227580667.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=oss@malat.biz \
/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).