* [PATCH] drivers: phy: fix memory leak in error handling
@ 2013-11-09 5:28 Michael Opdenacker
2013-11-11 9:01 ` Kishon Vijay Abraham I
0 siblings, 1 reply; 3+ messages in thread
From: Michael Opdenacker @ 2013-11-09 5:28 UTC (permalink / raw)
To: kishon; +Cc: linux-kernel, Michael Opdenacker
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>
---
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:
--
1.8.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers: phy: fix memory leak in error handling
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
2013-11-13 9:31 ` Michael Opdenacker
0 siblings, 1 reply; 3+ messages in thread
From: Kishon Vijay Abraham I @ 2013-11-11 9:01 UTC (permalink / raw)
To: Michael Opdenacker; +Cc: linux-kernel
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:
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers: phy: fix memory leak in error handling
2013-11-11 9:01 ` Kishon Vijay Abraham I
@ 2013-11-13 9:31 ` Michael Opdenacker
0 siblings, 0 replies; 3+ messages in thread
From: Michael Opdenacker @ 2013-11-13 9:31 UTC (permalink / raw)
To: Kishon Vijay Abraham I; +Cc: linux-kernel
Hi Kishon,
Thank you very much for reviewing my patch!
On 11/11/2013 10:01 AM, Kishon Vijay Abraham I wrote:
> A patch has already been sent for fixing this.
>
> https://git.kernel.org/cgit/linux/kernel/git/kishon/linux-phy.git/commit/?h=fixes
Great news! Thanks again,
Cheers,
Michael.
--
Michael Opdenacker, CEO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
+33 484 258 098
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-13 9:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2013-11-13 9:31 ` Michael Opdenacker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox