Skip to content

Commit

Permalink
net: phy: add locking to phy_read_mmd_indirect()/phy_write_mmd_indire…
Browse files Browse the repository at this point in the history
…ct()

The phy layer is missing locking for the above two functions - it
has been observed that two threads (userspace and the phy worker
thread) can race, entering the bus ->write or ->read functions
simultaneously.

This causes the FEC driver to initialise a completion while another
thread is waiting on it or while the interrupt is calling complete()
on it, which causes spinlock unlock-without-lock, spinlock lockups,
and completion timeouts.

Fixes: a59a4d1 ("phy: add the EEE support and the way to access to the MMD registers.")
Fixes: 0c1d77d ("net: libphy: Add phy specific function to access mmd phy registers")
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Russell King authored and David S. Miller committed Aug 25, 2015
1 parent bef0057 commit 05a7f58
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drivers/net/phy/phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,14 @@ int phy_read_mmd_indirect(struct phy_device *phydev, int prtad,
int value = -1;

if (phydrv->read_mmd_indirect == NULL) {
mmd_phy_indirect(phydev->bus, prtad, devad, addr);
struct mii_bus *bus = phydev->bus;

mutex_lock(&bus->mdio_lock);
mmd_phy_indirect(bus, prtad, devad, addr);

/* Read the content of the MMD's selected register */
value = phydev->bus->read(phydev->bus, addr, MII_MMD_DATA);
value = bus->read(bus, addr, MII_MMD_DATA);
mutex_unlock(&bus->mdio_lock);
} else {
value = phydrv->read_mmd_indirect(phydev, prtad, devad, addr);
}
Expand Down Expand Up @@ -1071,10 +1075,14 @@ void phy_write_mmd_indirect(struct phy_device *phydev, int prtad,
struct phy_driver *phydrv = phydev->drv;

if (phydrv->write_mmd_indirect == NULL) {
mmd_phy_indirect(phydev->bus, prtad, devad, addr);
struct mii_bus *bus = phydev->bus;

mutex_lock(&bus->mdio_lock);
mmd_phy_indirect(bus, prtad, devad, addr);

/* Write the data into MMD's selected register */
phydev->bus->write(phydev->bus, addr, MII_MMD_DATA, data);
bus->write(bus, addr, MII_MMD_DATA, data);
mutex_unlock(&bus->mdio_lock);
} else {
phydrv->write_mmd_indirect(phydev, prtad, devad, addr, data);
}
Expand Down

0 comments on commit 05a7f58

Please sign in to comment.