Commit af1a02aa authored by Andrew Lunn's avatar Andrew Lunn Committed by David S. Miller
Browse files

phy: phy_ethtool_ksettings_set: Lock the PHY while changing settings



There is a race condition where the PHY state machine can change
members of the phydev structure at the same time userspace requests a
change via ethtool. To prevent this, have phy_ethtool_ksettings_set
take the PHY lock.

Fixes: 2d55173e ("phy: add generic function to support ksetting support")
Reported-by: default avatarWalter Stoll <Walter.Stoll@duagon.com>
Suggested-by: default avatarWalter Stoll <Walter.Stoll@duagon.com>
Tested-by: default avatarWalter Stoll <Walter.Stoll@duagon.com>
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 707293a5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -798,6 +798,7 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
	      duplex != DUPLEX_FULL)))
		return -EINVAL;

	mutex_lock(&phydev->lock);
	phydev->autoneg = autoneg;

	if (autoneg == AUTONEG_DISABLE) {
@@ -814,8 +815,9 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
	phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl;

	/* Restart the PHY */
	phy_start_aneg(phydev);
	_phy_start_aneg(phydev);

	mutex_unlock(&phydev->lock);
	return 0;
}
EXPORT_SYMBOL(phy_ethtool_ksettings_set);