@@ -29,7 +29,7 @@ static void devm_phy_release(struct device *dev, void *res)
2929{
3030 struct phy * phy = * (struct phy * * )res ;
3131
32- phy_put (phy );
32+ phy_put (dev , phy );
3333}
3434
3535static void devm_phy_provider_release (struct device * dev , void * res )
@@ -566,12 +566,12 @@ struct phy *of_phy_get(struct device_node *np, const char *con_id)
566566EXPORT_SYMBOL_GPL (of_phy_get );
567567
568568/**
569- * phy_put () - release the PHY
570- * @phy: the phy returned by phy_get ()
569+ * of_phy_put () - release the PHY
570+ * @phy: the phy returned by of_phy_get ()
571571 *
572- * Releases a refcount the caller received from phy_get ().
572+ * Releases a refcount the caller received from of_phy_get ().
573573 */
574- void phy_put (struct phy * phy )
574+ void of_phy_put (struct phy * phy )
575575{
576576 if (!phy || IS_ERR (phy ))
577577 return ;
@@ -584,6 +584,20 @@ void phy_put(struct phy *phy)
584584 module_put (phy -> ops -> owner );
585585 put_device (& phy -> dev );
586586}
587+ EXPORT_SYMBOL_GPL (of_phy_put );
588+
589+ /**
590+ * phy_put() - release the PHY
591+ * @dev: device that wants to release this phy
592+ * @phy: the phy returned by phy_get()
593+ *
594+ * Releases a refcount the caller received from phy_get().
595+ */
596+ void phy_put (struct device * dev , struct phy * phy )
597+ {
598+ device_link_remove (dev , & phy -> dev );
599+ of_phy_put (phy );
600+ }
587601EXPORT_SYMBOL_GPL (phy_put );
588602
589603/**
@@ -651,6 +665,7 @@ struct phy *phy_get(struct device *dev, const char *string)
651665{
652666 int index = 0 ;
653667 struct phy * phy ;
668+ struct device_link * link ;
654669
655670 if (string == NULL ) {
656671 dev_WARN (dev , "missing string\n" );
@@ -672,6 +687,13 @@ struct phy *phy_get(struct device *dev, const char *string)
672687
673688 get_device (& phy -> dev );
674689
690+ link = device_link_add (dev , & phy -> dev , DL_FLAG_STATELESS );
691+ if (!link ) {
692+ dev_err (dev , "failed to create device link to %s\n" ,
693+ dev_name (phy -> dev .parent ));
694+ return ERR_PTR (- EINVAL );
695+ }
696+
675697 return phy ;
676698}
677699EXPORT_SYMBOL_GPL (phy_get );
@@ -765,6 +787,7 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
765787 const char * con_id )
766788{
767789 struct phy * * ptr , * phy ;
790+ struct device_link * link ;
768791
769792 ptr = devres_alloc (devm_phy_release , sizeof (* ptr ), GFP_KERNEL );
770793 if (!ptr )
@@ -776,6 +799,14 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
776799 devres_add (dev , ptr );
777800 } else {
778801 devres_free (ptr );
802+ return phy ;
803+ }
804+
805+ link = device_link_add (dev , & phy -> dev , DL_FLAG_STATELESS );
806+ if (!link ) {
807+ dev_err (dev , "failed to create device link to %s\n" ,
808+ dev_name (phy -> dev .parent ));
809+ return ERR_PTR (- EINVAL );
779810 }
780811
781812 return phy ;
@@ -798,6 +829,7 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
798829 int index )
799830{
800831 struct phy * * ptr , * phy ;
832+ struct device_link * link ;
801833
802834 ptr = devres_alloc (devm_phy_release , sizeof (* ptr ), GFP_KERNEL );
803835 if (!ptr )
@@ -819,6 +851,13 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
819851 * ptr = phy ;
820852 devres_add (dev , ptr );
821853
854+ link = device_link_add (dev , & phy -> dev , DL_FLAG_STATELESS );
855+ if (!link ) {
856+ dev_err (dev , "failed to create device link to %s\n" ,
857+ dev_name (phy -> dev .parent ));
858+ return ERR_PTR (- EINVAL );
859+ }
860+
822861 return phy ;
823862}
824863EXPORT_SYMBOL_GPL (devm_of_phy_get_by_index );
0 commit comments