mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] net: phy: do not crash on missing read_page()/write_page() ops
Date: Mon, 25 Mar 2024 12:02:14 +0100	[thread overview]
Message-ID: <20240325110214.3301152-1-s.hauer@pengutronix.de> (raw)

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




             reply	other threads:[~2024-03-25 11:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 11:02 Sascha Hauer [this message]
2024-04-03 11:25 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240325110214.3301152-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox