]> git.baikalelectronics.ru Git - kernel.git/commitdiff
phy: phy_ethtool_ksettings_get: Lock the phy for consistency
authorAndrew Lunn <andrew@lunn.ch>
Sun, 24 Oct 2021 19:48:02 +0000 (21:48 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 2 Nov 2021 18:46:14 +0000 (19:46 +0100)
commit c10a485c3de5ccbf1fff65a382cebcb2730c6b06 upstream.

The PHY structure should be locked while copying information out if
it, otherwise there is no guarantee of self consistency. Without the
lock the PHY state machine could be updating the structure.

Fixes: b8d3899eefb1 ("phy: add generic function to support ksetting support")
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/phy/phy.c

index b0b8a3ce82b689d013c963173732a1f4fad13125..168a36857036de869e0176b9dc809a546567f121 100644 (file)
@@ -367,6 +367,7 @@ EXPORT_SYMBOL(phy_ethtool_ksettings_set);
 void phy_ethtool_ksettings_get(struct phy_device *phydev,
                               struct ethtool_link_ksettings *cmd)
 {
+       mutex_lock(&phydev->lock);
        linkmode_copy(cmd->link_modes.supported, phydev->supported);
        linkmode_copy(cmd->link_modes.advertising, phydev->advertising);
        linkmode_copy(cmd->link_modes.lp_advertising, phydev->lp_advertising);
@@ -383,6 +384,7 @@ void phy_ethtool_ksettings_get(struct phy_device *phydev,
        cmd->base.autoneg = phydev->autoneg;
        cmd->base.eth_tp_mdix_ctrl = phydev->mdix_ctrl;
        cmd->base.eth_tp_mdix = phydev->mdix;
+       mutex_unlock(&phydev->lock);
 }
 EXPORT_SYMBOL(phy_ethtool_ksettings_get);