[PATCH v2025.09.y 38/58] net: phy: add NULL check for phy driver in page accessors
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Mar 13 06:25:22 PDT 2026
to_phy_driver() can return NULL if the device has no driver bound.
While phy_read_page() and phy_write_page() are only called on bound
devices in practice, the existing error messages already hint at
this possibility ("PHY driver not loaded?").
Add a NULL check for phydrv before dereferencing it, consistent with
the existing error handling.
(cherry picked from commit 9403ba1be4c82ced708a94efc8539e8202a90f57)
Reported-by: GCC 14.2 -fanalyzer
Co-authored-by: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Link: https://lore.barebox.org/20260216084253.3547270-7-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/net/phy/phy-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index b12f54ed3878..b30cb1dc7349 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -27,7 +27,7 @@ static int phy_read_page(struct phy_device *phydev)
{
struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver);
- if (!phydrv->read_page) {
+ if (!phydrv || !phydrv->read_page) {
dev_warn_once(&phydev->dev, "read_page callback not available, PHY driver not loaded?\n");
return -EOPNOTSUPP;
}
@@ -39,7 +39,7 @@ 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) {
+ if (!phydrv || !phydrv->write_page) {
dev_warn_once(&phydev->dev, "write_page callback not available, PHY driver not loaded?\n");
return -EOPNOTSUPP;
}
--
2.47.3
More information about the barebox
mailing list