From: Kishon Vijay Abraham I <kishon@ti.com>
To: Michael Opdenacker <michael.opdenacker@free-electrons.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drivers: phy: fix memory leak in error handling
Date: Mon, 11 Nov 2013 14:31:11 +0530 [thread overview]
Message-ID: <52809CD7.6080306@ti.com> (raw)
In-Reply-To: <1383974928-20730-1-git-send-email-michael.opdenacker@free-electrons.com>
Hi Michael,
On Saturday 09 November 2013 10:58 AM, Michael Opdenacker wrote:
> This fixes a memory leak in the phy_create() function.
>
> If ida_simple_get() returns with an error, the code jumps
> to the "err0" label without freeing the "phy" pointer.
>
> This patch introduces a new error management label to address this.
>
> Issue found with Coverity (CID 1127219)
>
> Signed-off-by: Michael Opdenacker <michael.opdenacker@free-electrons.com>
A patch has already been sent for fixing this.
https://git.kernel.org/cgit/linux/kernel/git/kishon/linux-phy.git/commit/?h=fixes
Thanks
Kishon
> ---
> drivers/phy/phy-core.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 03cf8fb81554..8ddffe84d905 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -453,7 +453,7 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
> if (id < 0) {
> dev_err(dev, "unable to get id\n");
> ret = id;
> - goto err0;
> + goto err1;
> }
>
> device_initialize(&phy->dev);
> @@ -468,11 +468,11 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
>
> ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id);
> if (ret)
> - goto err1;
> + goto err2;
>
> ret = device_add(&phy->dev);
> if (ret)
> - goto err1;
> + goto err2;
>
> if (pm_runtime_enabled(dev)) {
> pm_runtime_enable(&phy->dev);
> @@ -481,9 +481,11 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
>
> return phy;
>
> -err1:
> +err2:
> ida_remove(&phy_ida, phy->id);
> put_device(&phy->dev);
> +
> +err1:
> kfree(phy);
>
> err0:
>
next prev parent reply other threads:[~2013-11-11 9:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-09 5:28 [PATCH] drivers: phy: fix memory leak in error handling Michael Opdenacker
2013-11-11 9:01 ` Kishon Vijay Abraham I [this message]
2013-11-13 9:31 ` Michael Opdenacker
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=52809CD7.6080306@ti.com \
--to=kishon@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.opdenacker@free-electrons.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.