summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2024-03-25 12:02:14 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-04-03 13:25:32 +0200
commit8a9d15f9a0f49c1bb71bf2d156094608739854da (patch)
treec95597f8b7b1e5f3a7ba9e2239b63e68abb75e73
parent63d38f891a9ca38ef95c12a01c0e50fa1ff65692 (diff)
downloadbarebox-8a9d15f9a0f4.tar.gz
barebox-8a9d15f9a0f4.tar.xz
net: phy: do not crash on missing read_page()/write_page() ops
Normally phy_select_page() is only called from within the phy driver. The exception is the r8169 network driver. It calls phy_select_page() assuming that its internal phy is supported by the realtek phy driver which supports this operation. It can happen though that the internal phy is not yet supported by the realtek phy driver and thus support falls back to the generic phy driver. return gracefully in this case instead of crashing barebox. Link: https://lore.barebox.org/20240325110214.3301152-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/net/phy/phy-core.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index ab52de35b5..b12f54ed38 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -27,6 +27,11 @@ static int phy_read_page(struct phy_device *phydev)
{
struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver);
+ if (!phydrv->read_page) {
+ dev_warn_once(&phydev->dev, "read_page callback not available, PHY driver not loaded?\n");
+ return -EOPNOTSUPP;
+ }
+
return phydrv->read_page(phydev);
}
@@ -34,6 +39,11 @@ static int phy_write_page(struct phy_device *phydev, int page)
{
struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver);
+ if (!phydrv->write_page) {
+ dev_warn_once(&phydev->dev, "write_page callback not available, PHY driver not loaded?\n");
+ return -EOPNOTSUPP;
+ }
+
return phydrv->write_page(phydev, page);
}