summaryrefslogtreecommitdiff
path: root/drivers/phy
diff options
context:
space:
mode:
authorJean-Jacques Hiblot <jjhiblot@ti.com>2019-10-01 14:03:26 +0200
committerTom Rini <trini@konsulko.com>2019-10-31 07:22:53 -0400
commit4e1842988364446ba0cf2171d1eebb53c15bc44e (patch)
treedc5536f60fab7fc0a5ab37106c09c4302cd97c3d /drivers/phy
parent2ad98ab8f68c71e2db140c6d5f1020aa6fbacb9e (diff)
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. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Diffstat (limited to 'drivers/phy')
-rw-r--r--drivers/phy/phy-uclass.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
index a0ac30aa71..e201a90c8c 100644
--- a/drivers/phy/phy-uclass.c
+++ b/drivers/phy/phy-uclass.c
@@ -108,35 +108,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;
}