Skip to content

Commit

Permalink
phy: core: Fix error path in phy_create()
Browse files Browse the repository at this point in the history
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.

Cc: 3.13+ <stable@vger.kernel.org> # 3.13+
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Roger Quadros authored and Greg Kroah-Hartman committed Jul 12, 2014
1 parent bf5baf9 commit e73b49f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/phy/phy-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit e73b49f

Please sign in to comment.