[PATCH] net: phy: do not crash on missing read_page()/write_page() ops
Sascha Hauer
s.hauer at pengutronix.de
Mon Mar 25 04:02:14 PDT 2024
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.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/net/phy/phy-core.c | 10 ++++++++++
1 file changed, 10 insertions(+)
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);
}
--
2.39.2
More information about the barebox
mailing list