[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1383974928-20730-1-git-send-email-michael.opdenacker@free-electrons.com>
Date: Sat, 9 Nov 2013 06:28:48 +0100
From: Michael Opdenacker <michael.opdenacker@...e-electrons.com>
To: kishon@...com
Cc: linux-kernel@...r.kernel.org,
Michael Opdenacker <michael.opdenacker@...e-electrons.com>
Subject: [PATCH] drivers: phy: fix memory leak in error handling
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@...e-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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists