net: dsa: Fix NULL checking in dsa_slave_set_eee() [Linux 5.0]

net: dsa: Fix NULL checking in dsa_slave_set_eee() [Linux 5.0]

This Linux kernel change "net: dsa: Fix NULL checking in dsa_slave_set_eee()" is included in the Linux 5.0 release. This change is authored by Dan Carpenter <dan.carpenter [at] oracle.com> on Wed Feb 6 18:35:15 2019 +0300. The commit for this change in Linux stable tree is 00670cb (patch).

net: dsa: Fix NULL checking in dsa_slave_set_eee()

This function can't succeed if dp->pl is NULL.  It will Oops inside the
call to return phylink_ethtool_get_eee(dp->pl, e);

Fixes: 1be52e97ed3e ("dsa: slave: eee: Allow ports to use phylink")
Signed-off-by: Dan Carpenter <[email protected]>
Reviewed-by: Florian Fainelli <[email protected]>
Reviewed-by: Vivien Didelot <[email protected]>
Signed-off-by: David S. Miller <[email protected]>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 net/dsa/slave.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index b5e4482..a1c9fe1 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -642,7 +642,7 @@ static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
    int ret;

    /* Port's PHY and MAC both need to be EEE capable */
-   if (!dev->phydev && !dp->pl)
+   if (!dev->phydev || !dp->pl)
        return -ENODEV;

    if (!ds->ops->set_mac_eee)
@@ -662,7 +662,7 @@ static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
    int ret;

    /* Port's PHY and MAC both need to be EEE capable */
-   if (!dev->phydev && !dp->pl)
+   if (!dev->phydev || !dp->pl)
        return -ENODEV;

    if (!ds->ops->get_mac_eee)

Leave a Reply

Your email address will not be published. Required fields are marked *