diff mbox

[5/8] phy: core: Fix error path in phy_create()

Message ID 1404715705-5041-6-git-send-email-kishon@ti.com
State Superseded
Headers show

Commit Message

Kishon Vijay Abraham I July 7, 2014, 6:48 a.m. UTC
From: Roger Quadros <rogerq@ti.com>

Prevent resources from being freed twice in case device_add() call
fails within phy_create(). Also use ida_simple_remove() instead of
ida_remove() as we had used ida_simple_get() to allocate the ida.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/phy/phy-core.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Greg KH July 8, 2014, 1:45 a.m. UTC | #1
On Mon, Jul 07, 2014 at 12:18:22PM +0530, Kishon Vijay Abraham I wrote:
> From: Roger Quadros <rogerq@ti.com>
> 
> Prevent resources from being freed twice in case device_add() call
> fails within phy_create(). Also use ida_simple_remove() instead of
> ida_remove() as we had used ida_simple_get() to allocate the ida.
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/phy/phy-core.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

Is this a problem in older kernels as well?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Kishon Vijay Abraham I July 8, 2014, 6:14 a.m. UTC | #2
Hi,

On Tuesday 08 July 2014 07:15 AM, Greg KH wrote:
> On Mon, Jul 07, 2014 at 12:18:22PM +0530, Kishon Vijay Abraham I wrote:
>> From: Roger Quadros <rogerq@ti.com>
>>
>> Prevent resources from being freed twice in case device_add() call
>> fails within phy_create(). Also use ida_simple_remove() instead of
>> ida_remove() as we had used ida_simple_get() to allocate the ida.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>  drivers/phy/phy-core.c |    7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> Is this a problem in older kernels as well?

yeah. Will send it for stable kernel.

Thanks
Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index c64a2f3..49c4465 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -614,8 +614,9 @@  struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
 	return phy;
 
 put_dev:
-	put_device(&phy->dev);
-	ida_remove(&phy_ida, phy->id);
+	put_device(&phy->dev);  /* calls phy_release() which frees resources */
+	return ERR_PTR(ret);
+
 free_phy:
 	kfree(phy);
 	return ERR_PTR(ret);
@@ -799,7 +800,7 @@  static void phy_release(struct device *dev)
 
 	phy = to_phy(dev);
 	dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
-	ida_remove(&phy_ida, phy->id);
+	ida_simple_remove(&phy_ida, phy->id);
 	kfree(phy);
 }