Skip to content

Commit

Permalink
net: mscc: ocelot: fix race between ndo_get_stats64 and ocelot_check_…
Browse files Browse the repository at this point in the history
…stats_work

The 2 methods can run concurrently, and one will change the window of
counters (SYS_STAT_CFG_STAT_VIEW) that the other sees. The fix is
similar to what commit 7fbf679 ("net: mscc: ocelot: fix mutex lock
error during ethtool stats read") has done for ethtool -S.

Fixes: a556c76 ("net: mscc: Add initial Ocelot switch support")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Vladimir Oltean authored and Jakub Kicinski committed Aug 18, 2022
1 parent 22d842e commit 18d8e67
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/net/ethernet/mscc/ocelot_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ static void ocelot_get_stats64(struct net_device *dev,
struct ocelot *ocelot = priv->port.ocelot;
int port = priv->port.index;

spin_lock(&ocelot->stats_lock);

/* Configure the port to read the stats from */
ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port),
SYS_STAT_CFG);
Expand Down Expand Up @@ -758,6 +760,8 @@ static void ocelot_get_stats64(struct net_device *dev,
stats->tx_dropped = ocelot_read(ocelot, SYS_COUNT_TX_DROPS) +
ocelot_read(ocelot, SYS_COUNT_TX_AGING);
stats->collisions = ocelot_read(ocelot, SYS_COUNT_TX_COLLISION);

spin_unlock(&ocelot->stats_lock);
}

static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
Expand Down

0 comments on commit 18d8e67

Please sign in to comment.