drivers: phy: fix memory leak in error handling
PATCH 1/1 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)
--- drivers/phy/phy-core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/phy/phy-core.c +6 -4
@@ -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:
Signature · 1 line
1.8.1.2
Hi Michael,
Quoted 10 lines · 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 <[email protected]>
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
Quoted 45 lines
--- drivers/phy/phy-core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/phy/phy-core.c +6
-4@@ -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:
Hi Kishon,
Thank you very much for reviewing my patch!
Quoted 3 lines · Kishon Vijay Abraham I
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.
Signature · 4 lines
Michael Opdenacker, CEO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com +33 484 258 098