Skip to content

Commit 7004b26

Browse files
Jijie Shaokuba-moo
authored andcommitted
net: hibmcge: fix the division by zero issue
When the network port is down, the queue is released, and ring->len is 0. In debugfs, hbg_get_queue_used_num() will be called, which may lead to a division by zero issue. This patch adds a check, if ring->len is 0, hbg_get_queue_used_num() directly returns 0. Fixes: 40735e7 ("net: hibmcge: Implement .ndo_start_xmit function") Signed-off-by: Jijie Shao <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c875503 commit 7004b26

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ static inline bool hbg_fifo_is_full(struct hbg_priv *priv, enum hbg_dir dir)
2929

3030
static inline u32 hbg_get_queue_used_num(struct hbg_ring *ring)
3131
{
32-
return (ring->ntu + ring->len - ring->ntc) % ring->len;
32+
u32 len = READ_ONCE(ring->len);
33+
34+
if (!len)
35+
return 0;
36+
37+
return (READ_ONCE(ring->ntu) + len - READ_ONCE(ring->ntc)) % len;
3338
}
3439

3540
netdev_tx_t hbg_net_start_xmit(struct sk_buff *skb, struct net_device *netdev);

0 commit comments

Comments
 (0)