Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alex Marginean and committed by
David S. Miller
3e41d04e 6cbdcf25

+2 -2
+2 -2
drivers/net/phy/phy-core.c
··· 387 387 if (regnum > (u16)~0 || devad > 32) 388 388 return -EINVAL; 389 389 390 - if (phydev->drv->read_mmd) { 390 + if (phydev->drv && phydev->drv->read_mmd) { 391 391 val = phydev->drv->read_mmd(phydev, devad, regnum); 392 392 } else if (phydev->is_c45) { 393 393 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff); ··· 444 444 if (regnum > (u16)~0 || devad > 32) 445 445 return -EINVAL; 446 446 447 - if (phydev->drv->write_mmd) { 447 + if (phydev->drv && phydev->drv->write_mmd) { 448 448 ret = phydev->drv->write_mmd(phydev, devad, regnum, val); 449 449 } else if (phydev->is_c45) { 450 450 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);