]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
ethtool: Protect {get, set}_phy_tunable with PHY device mutex
authorFlorian Fainelli <f.fainelli@gmail.com>
Tue, 22 Nov 2016 21:55:31 +0000 (13:55 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 24 Nov 2016 21:02:32 +0000 (16:02 -0500)
PHY drivers should be able to rely on the caller of {get,set}_tunable to
have acquired the PHY device mutex, in order to both serialize against
concurrent calls of these functions, but also against PHY state machine
changes. All ethtool PHY-level functions do this, except
{get,set}_tunable, so we make them consistent here as well.

We need to update the Microsemi PHY driver in the same commit to avoid
introducing either deadlocks, or lack of proper locking.

Fixes: 968ad9da7e0e ("ethtool: Implements ETHTOOL_PHY_GTUNABLE/ETHTOOL_PHY_STUNABLE")
Fixes: 310d9ad57ae0 ("net: phy: Add downshift get/set support in Microsemi PHYs driver")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Allan W. Nielsen <allan.nielsen@microsemi.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/mscc.c
net/core/ethtool.c

index 92018ba6209ef05ea1b3ad2722613c10b4f05fa2..7a3740c7bf6d128f34b8e5ae3b2c6e6d96b162a5 100644 (file)
@@ -115,10 +115,9 @@ static int vsc85xx_downshift_get(struct phy_device *phydev, u8 *count)
        int rc;
        u16 reg_val;
 
-       mutex_lock(&phydev->lock);
        rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED);
        if (rc != 0)
-               goto out_unlock;
+               goto out;
 
        reg_val = phy_read(phydev, MSCC_PHY_ACTIPHY_CNTL);
        reg_val &= DOWNSHIFT_CNTL_MASK;
@@ -128,9 +127,7 @@ static int vsc85xx_downshift_get(struct phy_device *phydev, u8 *count)
                *count = ((reg_val & ~DOWNSHIFT_EN) >> DOWNSHIFT_CNTL_POS) + 2;
        rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD);
 
-out_unlock:
-       mutex_unlock(&phydev->lock);
-
+out:
        return rc;
 }
 
@@ -150,23 +147,20 @@ static int vsc85xx_downshift_set(struct phy_device *phydev, u8 count)
                count = (((count - 2) << DOWNSHIFT_CNTL_POS) | DOWNSHIFT_EN);
        }
 
-       mutex_lock(&phydev->lock);
        rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED);
        if (rc != 0)
-               goto out_unlock;
+               goto out;
 
        reg_val = phy_read(phydev, MSCC_PHY_ACTIPHY_CNTL);
        reg_val &= ~(DOWNSHIFT_CNTL_MASK);
        reg_val |= count;
        rc = phy_write(phydev, MSCC_PHY_ACTIPHY_CNTL, reg_val);
        if (rc != 0)
-               goto out_unlock;
+               goto out;
 
        rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD);
 
-out_unlock:
-       mutex_unlock(&phydev->lock);
-
+out:
        return rc;
 }
 
index e9b4556751ff5e0c0df90909f815ad0a5249e473..0adb3bec5b5a542a77c17d9bbaaa2d8327f36919 100644 (file)
@@ -2466,7 +2466,9 @@ static int get_phy_tunable(struct net_device *dev, void __user *useraddr)
        data = kmalloc(tuna.len, GFP_USER);
        if (!data)
                return -ENOMEM;
+       mutex_lock(&phydev->lock);
        ret = phydev->drv->get_tunable(phydev, &tuna, data);
+       mutex_unlock(&phydev->lock);
        if (ret)
                goto out;
        useraddr += sizeof(tuna);
@@ -2501,7 +2503,9 @@ static int set_phy_tunable(struct net_device *dev, void __user *useraddr)
        ret = -EFAULT;
        if (copy_from_user(data, useraddr, tuna.len))
                goto out;
+       mutex_lock(&phydev->lock);
        ret = phydev->drv->set_tunable(phydev, &tuna, data);
+       mutex_unlock(&phydev->lock);
 
 out:
        kfree(data);