Commit 3e41d04e authored by Alex Marginean's avatar Alex Marginean Committed by David S. Miller

net: phy: don't crash in phy_read/_write_mmd without a PHY driver

The APIs can be used by Ethernet drivers without actually loading a PHY
driver. This may become more widespread in the future with 802.3z
compatible MAC PCS devices being locally driven by the MAC driver when
configuring for a PHY mode with in-band negotiation.

Check that drv is not NULL before reading from it.
Signed-off-by: default avatarAlex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6cbdcf25
...@@ -387,7 +387,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) ...@@ -387,7 +387,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
if (regnum > (u16)~0 || devad > 32) if (regnum > (u16)~0 || devad > 32)
return -EINVAL; return -EINVAL;
if (phydev->drv->read_mmd) { if (phydev->drv && phydev->drv->read_mmd) {
val = phydev->drv->read_mmd(phydev, devad, regnum); val = phydev->drv->read_mmd(phydev, devad, regnum);
} else if (phydev->is_c45) { } else if (phydev->is_c45) {
u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff); u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
...@@ -444,7 +444,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) ...@@ -444,7 +444,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
if (regnum > (u16)~0 || devad > 32) if (regnum > (u16)~0 || devad > 32)
return -EINVAL; return -EINVAL;
if (phydev->drv->write_mmd) { if (phydev->drv && phydev->drv->write_mmd) {
ret = phydev->drv->write_mmd(phydev, devad, regnum, val); ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
} else if (phydev->is_c45) { } else if (phydev->is_c45) {
u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff); u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment