Skip to content

Commit 47a9b5e

Browse files
danish-tiPaolo Abeni
authored andcommitted
net: ti: icssg-prueth: Add lock to stats
Currently the API emac_update_hardware_stats() reads different ICSSG stats without any lock protection. This API gets called by .ndo_get_stats64() which is only under RCU protection and nothing else. Add lock to this API so that the reading of statistics happens during lock. Fixes: c1e10d5 ("net: ti: icssg-prueth: Add ICSSG Stats") Signed-off-by: MD Danish Anwar <danishanwar@ti.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20250314102721.1394366-1-danishanwar@ti.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent f3009d0 commit 47a9b5e

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

drivers/net/ethernet/ti/icssg/icssg_prueth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ static int prueth_probe(struct platform_device *pdev)
16791679
}
16801680

16811681
spin_lock_init(&prueth->vtbl_lock);
1682+
spin_lock_init(&prueth->stats_lock);
16821683
/* setup netdev interfaces */
16831684
if (eth0_node) {
16841685
ret = prueth_netdev_init(prueth, eth0_node);

drivers/net/ethernet/ti/icssg/icssg_prueth.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ struct prueth {
305305
int default_vlan;
306306
/** @vtbl_lock: Lock for vtbl in shared memory */
307307
spinlock_t vtbl_lock;
308+
/** @stats_lock: Lock for reading icssg stats */
309+
spinlock_t stats_lock;
308310
};
309311

310312
struct emac_tx_ts_response {

drivers/net/ethernet/ti/icssg/icssg_stats.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ void emac_update_hardware_stats(struct prueth_emac *emac)
2626
u32 val, reg;
2727
int i;
2828

29+
spin_lock(&prueth->stats_lock);
30+
2931
for (i = 0; i < ARRAY_SIZE(icssg_all_miig_stats); i++) {
3032
regmap_read(prueth->miig_rt,
3133
base + icssg_all_miig_stats[i].offset,
@@ -51,6 +53,8 @@ void emac_update_hardware_stats(struct prueth_emac *emac)
5153
emac->pa_stats[i] += val;
5254
}
5355
}
56+
57+
spin_unlock(&prueth->stats_lock);
5458
}
5559

5660
void icssg_stats_work_handler(struct work_struct *work)

0 commit comments

Comments
 (0)