UPSTREAM: drivers: phy: Handle gracefully NULL pointers
For some controllers PHYs can be optional. Handling NULL pointers without crashing nor failing, makes it easy to handle optional PHYs. Change-Id: I11c95af8c1b54f2dad41891f6d0edb8d9fac6606 Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Signed-off-by: Wyon Bi <bivvy.bi@rock-chips.com> (cherry picked from commit 4e1842988364446ba0cf2171d1eebb53c15bc44e)
This commit is contained in:
parent
0220733d75
commit
1bac1f3947
|
|
@ -98,35 +98,55 @@ int generic_phy_get_by_name(struct udevice *dev, const char *phy_name,
|
|||
|
||||
int generic_phy_init(struct phy *phy)
|
||||
{
|
||||
struct phy_ops const *ops = phy_dev_ops(phy->dev);
|
||||
struct phy_ops const *ops;
|
||||
|
||||
if (!phy)
|
||||
return 0;
|
||||
ops = phy_dev_ops(phy->dev);
|
||||
|
||||
return ops->init ? ops->init(phy) : 0;
|
||||
}
|
||||
|
||||
int generic_phy_reset(struct phy *phy)
|
||||
{
|
||||
struct phy_ops const *ops = phy_dev_ops(phy->dev);
|
||||
struct phy_ops const *ops;
|
||||
|
||||
if (!phy)
|
||||
return 0;
|
||||
ops = phy_dev_ops(phy->dev);
|
||||
|
||||
return ops->reset ? ops->reset(phy) : 0;
|
||||
}
|
||||
|
||||
int generic_phy_exit(struct phy *phy)
|
||||
{
|
||||
struct phy_ops const *ops = phy_dev_ops(phy->dev);
|
||||
struct phy_ops const *ops;
|
||||
|
||||
if (!phy)
|
||||
return 0;
|
||||
ops = phy_dev_ops(phy->dev);
|
||||
|
||||
return ops->exit ? ops->exit(phy) : 0;
|
||||
}
|
||||
|
||||
int generic_phy_power_on(struct phy *phy)
|
||||
{
|
||||
struct phy_ops const *ops = phy_dev_ops(phy->dev);
|
||||
struct phy_ops const *ops;
|
||||
|
||||
if (!phy)
|
||||
return 0;
|
||||
ops = phy_dev_ops(phy->dev);
|
||||
|
||||
return ops->power_on ? ops->power_on(phy) : 0;
|
||||
}
|
||||
|
||||
int generic_phy_power_off(struct phy *phy)
|
||||
{
|
||||
struct phy_ops const *ops = phy_dev_ops(phy->dev);
|
||||
struct phy_ops const *ops;
|
||||
|
||||
if (!phy)
|
||||
return 0;
|
||||
ops = phy_dev_ops(phy->dev);
|
||||
|
||||
return ops->power_off ? ops->power_off(phy) : 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ static inline int generic_phy_get_by_name(struct udevice *user, const char *phy_
|
|||
*/
|
||||
static inline bool generic_phy_valid(struct phy *phy)
|
||||
{
|
||||
return phy->dev != NULL;
|
||||
return phy && phy->dev;
|
||||
}
|
||||
|
||||
#endif /*__GENERIC_PHY_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue