Commit 5435bb0967609527ca436357a2d996a0420a7d87

Authored by Roger Quadros
Committed by Greg Kroah-Hartman
1 parent d4989c47ab

phy: core: Fix error path in phy_create()

commit e73b49f1c4e75c44d62585cc3e5b9c7894b61c32 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 4 additions and 3 deletions Side-by-side Diff

drivers/phy/phy-core.c
... ... @@ -553,8 +553,9 @@
553 553 return phy;
554 554  
555 555 put_dev:
556   - put_device(&phy->dev);
557   - ida_remove(&phy_ida, phy->id);
  556 + put_device(&phy->dev); /* calls phy_release() which frees resources */
  557 + return ERR_PTR(ret);
  558 +
558 559 free_phy:
559 560 kfree(phy);
560 561 return ERR_PTR(ret);
... ... @@ -738,7 +739,7 @@
738 739  
739 740 phy = to_phy(dev);
740 741 dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
741   - ida_remove(&phy_ida, phy->id);
  742 + ida_simple_remove(&phy_ida, phy->id);
742 743 kfree(phy);
743 744 }
744 745