1 From: Russell King <rmk+kernel@armlinux.org.uk>
2 Date: Wed, 4 Jan 2017 21:00:51 +0000
3 Subject: [PATCH] net: phy: avoid setting unsupported EEE advertisments
5 We currently allow userspace to set any EEE advertisments it desires,
6 whether or not the PHY supports them. For example:
8 # ethtool --set-eee eth1 advertise 0xffffffff
9 # ethtool --show-eee eth1
10 EEE Settings for eth1:
13 Supported EEE link modes: 100baseT/Full
16 Advertised EEE link modes: 100baseT/Full
23 Clearly, this is not sane, we should only allow link modes that are
24 supported to be advertised (as we do elsewhere.) Ensure that we mask
25 the MDIO_AN_EEE_ADV value with the capabilities retrieved from the
26 MDIO_PCS_EEE_ABLE register.
28 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
31 --- a/drivers/net/phy/phy.c
32 +++ b/drivers/net/phy/phy.c
33 @@ -1343,11 +1343,16 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);
35 int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data)
37 - int val = ethtool_adv_to_mmd_eee_adv_t(data->advertised);
40 - phy_write_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN, val);
41 + /* Get Supported EEE */
42 + cap = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE);
47 + adv = ethtool_adv_to_mmd_eee_adv_t(data->advertised) & cap;
49 + return phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, adv);
51 EXPORT_SYMBOL(phy_ethtool_set_eee);