aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/phy/phy-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/phy/phy-core.c')
-rw-r--r--drivers/phy/phy-core.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index fc48fac003a6..8c7f27db6ad3 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -636,8 +636,9 @@ EXPORT_SYMBOL_GPL(devm_of_phy_get);
636 * @np: node containing the phy 636 * @np: node containing the phy
637 * @index: index of the phy 637 * @index: index of the phy
638 * 638 *
639 * Gets the phy using _of_phy_get(), and associates a device with it using 639 * Gets the phy using _of_phy_get(), then gets a refcount to it,
640 * devres. On driver detach, release function is invoked on the devres data, 640 * and associates a device with it using devres. On driver detach,
641 * release function is invoked on the devres data,
641 * then, devres data is freed. 642 * then, devres data is freed.
642 * 643 *
643 */ 644 */
@@ -651,13 +652,21 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
651 return ERR_PTR(-ENOMEM); 652 return ERR_PTR(-ENOMEM);
652 653
653 phy = _of_phy_get(np, index); 654 phy = _of_phy_get(np, index);
654 if (!IS_ERR(phy)) { 655 if (IS_ERR(phy)) {
655 *ptr = phy;
656 devres_add(dev, ptr);
657 } else {
658 devres_free(ptr); 656 devres_free(ptr);
657 return phy;
659 } 658 }
660 659
660 if (!try_module_get(phy->ops->owner)) {
661 devres_free(ptr);
662 return ERR_PTR(-EPROBE_DEFER);
663 }
664
665 get_device(&phy->dev);
666
667 *ptr = phy;
668 devres_add(dev, ptr);
669
661 return phy; 670 return phy;
662} 671}
663EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); 672EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);