[net,v3,4/4] net: phy: c45: genphy_c45_ethtool_set_eee: validate EEE link modes

Message ID 20230222055043.113711-5-o.rempel@pengutronix.de
State New
Headers
Series net: phy: EEE fixes |

Commit Message

Oleksij Rempel Feb. 22, 2023, 5:50 a.m. UTC
  Currently, it is possible to let some PHYs to advertise not supported
EEE link modes. So, validate them before overwriting existing
configuration.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/phy/phy-c45.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
  

Comments

Russell King (Oracle) Feb. 23, 2023, 9:55 a.m. UTC | #1
On Wed, Feb 22, 2023 at 06:50:43AM +0100, Oleksij Rempel wrote:
> Currently, it is possible to let some PHYs to advertise not supported
> EEE link modes. So, validate them before overwriting existing
> configuration.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!
  

Patch

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index 8717c122e2f3..3813b86689d0 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -1438,12 +1438,23 @@  int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
 	int ret;
 
 	if (data->eee_enabled) {
-		if (data->advertised)
+		if (data->advertised) {
+			__ETHTOOL_DECLARE_LINK_MODE_MASK(adv);
+
+			ethtool_convert_legacy_u32_to_link_mode(adv,
+								data->advertised);
+			linkmode_andnot(adv, adv, phydev->supported_eee);
+			if (!linkmode_empty(adv)) {
+				phydev_warn(phydev, "At least some EEE link modes are not supported.\n");
+				return -EINVAL;
+			}
+
 			ethtool_convert_legacy_u32_to_link_mode(phydev->advertising_eee,
 								data->advertised);
-		else
+		} else {
 			linkmode_copy(phydev->advertising_eee,
 				      phydev->supported_eee);
+		}
 
 		phydev->eee_enabled = true;
 	} else {