net: phylink: cleanup ksettings_set

We only need to fiddle about with the supported mask after we have
validated the user's requested parameters. Simplify and streamline the
code by moving the linkmode copy and update of the autoneg bit after
validating the user's request.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Russell King (Oracle) 2021-07-20 12:15:26 +01:00 committed by David S. Miller
parent 3389d3027f
commit 7cefb0b0e9

View file

@ -1458,15 +1458,11 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
return phy_ethtool_ksettings_set(pl->phydev, kset); return phy_ethtool_ksettings_set(pl->phydev, kset);
} }
linkmode_copy(support, pl->supported);
config = pl->link_config; config = pl->link_config;
config.an_enabled = kset->base.autoneg == AUTONEG_ENABLE;
/* Mask out unsupported advertisements, and force the autoneg bit */ /* Mask out unsupported advertisements */
linkmode_and(config.advertising, kset->link_modes.advertising, linkmode_and(config.advertising, kset->link_modes.advertising,
support); pl->supported);
linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising,
config.an_enabled);
/* FIXME: should we reject autoneg if phy/mac does not support it? */ /* FIXME: should we reject autoneg if phy/mac does not support it? */
switch (kset->base.autoneg) { switch (kset->base.autoneg) {
@ -1475,7 +1471,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
* duplex. * duplex.
*/ */
s = phy_lookup_setting(kset->base.speed, kset->base.duplex, s = phy_lookup_setting(kset->base.speed, kset->base.duplex,
support, false); pl->supported, false);
if (!s) if (!s)
return -EINVAL; return -EINVAL;
@ -1516,6 +1512,12 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
/* We have ruled out the case with a PHY attached, and the /* We have ruled out the case with a PHY attached, and the
* fixed-link cases. All that is left are in-band links. * fixed-link cases. All that is left are in-band links.
*/ */
config.an_enabled = kset->base.autoneg == AUTONEG_ENABLE;
linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising,
config.an_enabled);
/* Validate without changing the current supported mask. */
linkmode_copy(support, pl->supported);
if (phylink_validate(pl, support, &config)) if (phylink_validate(pl, support, &config))
return -EINVAL; return -EINVAL;