Skip to content

Commit 849704b

Browse files
aloktiwakuba-moo
authored andcommitted
net: thunderx: avoid direct MTU assignment after WRITE_ONCE()
The current logic in nicvf_change_mtu() writes the new MTU to netdev->mtu using WRITE_ONCE() before verifying if the hardware update succeeds. However on hardware update failure, it attempts to revert to the original MTU using a direct assignment (netdev->mtu = orig_mtu) which violates the intended of WRITE_ONCE protection introduced in commit 1eb2cde ("net: annotate writes on dev->mtu from ndo_change_mtu()") Additionally, WRITE_ONCE(netdev->mtu, new_mtu) is unnecessarily performed even when the device is not running. Fix this by: Only writing netdev->mtu after successfully updating the hardware. Skipping hardware update when the device is down, and setting MTU directly. Remove unused variable orig_mtu. This ensures that all writes to netdev->mtu are consistent with WRITE_ONCE expectations and avoids unintended state corruption on failure paths. Signed-off-by: Alok Tiwari <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d556838 commit 849704b

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

drivers/net/ethernet/cavium/thunder/nicvf_main.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,6 @@ int nicvf_open(struct net_device *netdev)
15781578
static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
15791579
{
15801580
struct nicvf *nic = netdev_priv(netdev);
1581-
int orig_mtu = netdev->mtu;
15821581

15831582
/* For now just support only the usual MTU sized frames,
15841583
* plus some headroom for VLAN, QinQ.
@@ -1589,15 +1588,10 @@ static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
15891588
return -EINVAL;
15901589
}
15911590

1592-
WRITE_ONCE(netdev->mtu, new_mtu);
1593-
1594-
if (!netif_running(netdev))
1595-
return 0;
1596-
1597-
if (nicvf_update_hw_max_frs(nic, new_mtu)) {
1598-
netdev->mtu = orig_mtu;
1591+
if (netif_running(netdev) && nicvf_update_hw_max_frs(nic, new_mtu))
15991592
return -EINVAL;
1600-
}
1593+
1594+
WRITE_ONCE(netdev->mtu, new_mtu);
16011595

16021596
return 0;
16031597
}

0 commit comments

Comments
 (0)