layerscape: add patches-5.4
[openwrt/staging/stintel.git] / target / linux / layerscape / patches-5.4 / 701-net-0391-drivers-net-phy-don-t-crash-in-phy_read-_write_mmd-w.patch
1 From 8e515a39805c013229698e1a142e16701f07edf9 Mon Sep 17 00:00:00 2001
2 From: Alex Marginean <alexandru.marginean@nxp.com>
3 Date: Tue, 7 Jan 2020 16:50:31 +0200
4 Subject: [PATCH] drivers: net: phy: don't crash in phy_read/_write_mmd without
5 a PHY driver
6
7 The APIs can be used by Ethernet drivers to configure internal PHYs
8 without actually loading a PHY driver. Check that drv is not NULL before
9 reading from it.
10
11 Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
12 ---
13 drivers/net/phy/phy-core.c | 4 ++--
14 1 file changed, 2 insertions(+), 2 deletions(-)
15
16 --- a/drivers/net/phy/phy-core.c
17 +++ b/drivers/net/phy/phy-core.c
18 @@ -379,7 +379,7 @@ int __phy_read_mmd(struct phy_device *ph
19 if (regnum > (u16)~0 || devad > 32)
20 return -EINVAL;
21
22 - if (phydev->drv->read_mmd) {
23 + if (phydev->drv && phydev->drv->read_mmd) {
24 val = phydev->drv->read_mmd(phydev, devad, regnum);
25 } else if (phydev->is_c45) {
26 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
27 @@ -436,7 +436,7 @@ int __phy_write_mmd(struct phy_device *p
28 if (regnum > (u16)~0 || devad > 32)
29 return -EINVAL;
30
31 - if (phydev->drv->write_mmd) {
32 + if (phydev->drv && phydev->drv->write_mmd) {
33 ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
34 } else if (phydev->is_c45) {
35 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);