Skip to content

Commit 6b67d4d

Browse files
hanzyddavem330
authored andcommitted
net: usb: lan78xx: don't modify phy_device state concurrently
Currently phy_device state could be left in inconsistent state shown by following alert message[1]. This is because phy_read_status could be called concurrently from lan78xx_delayedwork, phy_state_machine and __ethtool_get_link. Fix this by making sure that phy_device state is updated atomically. [1] lan78xx 1-1.1.1:1.0 eth0: No phy led trigger registered for speed(-1) Signed-off-by: Ivan T. Ivanov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 396492b commit 6b67d4d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/net/usb/lan78xx.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,17 +1154,20 @@ static int lan78xx_link_reset(struct lan78xx_net *dev)
11541154
{
11551155
struct phy_device *phydev = dev->net->phydev;
11561156
struct ethtool_link_ksettings ecmd;
1157-
int ladv, radv, ret;
1157+
int ladv, radv, ret, link;
11581158
u32 buf;
11591159

11601160
/* clear LAN78xx interrupt status */
11611161
ret = lan78xx_write_reg(dev, INT_STS, INT_STS_PHY_INT_);
11621162
if (unlikely(ret < 0))
11631163
return -EIO;
11641164

1165+
mutex_lock(&phydev->lock);
11651166
phy_read_status(phydev);
1167+
link = phydev->link;
1168+
mutex_unlock(&phydev->lock);
11661169

1167-
if (!phydev->link && dev->link_on) {
1170+
if (!link && dev->link_on) {
11681171
dev->link_on = false;
11691172

11701173
/* reset MAC */
@@ -1177,7 +1180,7 @@ static int lan78xx_link_reset(struct lan78xx_net *dev)
11771180
return -EIO;
11781181

11791182
del_timer(&dev->stat_monitor);
1180-
} else if (phydev->link && !dev->link_on) {
1183+
} else if (link && !dev->link_on) {
11811184
dev->link_on = true;
11821185

11831186
phy_ethtool_ksettings_get(phydev, &ecmd);
@@ -1466,9 +1469,14 @@ static int lan78xx_set_eee(struct net_device *net, struct ethtool_eee *edata)
14661469

14671470
static u32 lan78xx_get_link(struct net_device *net)
14681471
{
1472+
u32 link;
1473+
1474+
mutex_lock(&net->phydev->lock);
14691475
phy_read_status(net->phydev);
1476+
link = net->phydev->link;
1477+
mutex_unlock(&net->phydev->lock);
14701478

1471-
return net->phydev->link;
1479+
return link;
14721480
}
14731481

14741482
static void lan78xx_get_drvinfo(struct net_device *net,

0 commit comments

Comments
 (0)