mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net: phy: do not crash on missing read_page()/write_page() ops
@ 2024-03-25 11:02 Sascha Hauer
  2024-04-03 11:25 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2024-03-25 11:02 UTC (permalink / raw)
  To: Barebox List

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@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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: phy: do not crash on missing read_page()/write_page() ops
  2024-03-25 11:02 [PATCH] net: phy: do not crash on missing read_page()/write_page() ops Sascha Hauer
@ 2024-04-03 11:25 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-04-03 11:25 UTC (permalink / raw)
  To: Barebox List, Sascha Hauer


On Mon, 25 Mar 2024 12:02:14 +0100, Sascha Hauer wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] net: phy: do not crash on missing read_page()/write_page() ops
      https://git.pengutronix.de/cgit/barebox/commit/?id=8a9d15f9a0f4 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-03 11:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-25 11:02 [PATCH] net: phy: do not crash on missing read_page()/write_page() ops Sascha Hauer
2024-04-03 11:25 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox