Skip to content

Commit 6571ebc

Browse files
t-sakidavem330
authored andcommitted
net: altera_tse: fix msgdma_tx_completion on non-zero fill_level case
If fill_level was not zero and status was not BUSY, result of "tx_prod - tx_cons - inuse" might be zero. Subtracting 1 unconditionally results invalid negative return value on this case. Make sure not to return an negative value. Signed-off-by: Tomonori Sakita <[email protected]> Signed-off-by: Atsushi Nemoto <[email protected]> Reviewed-by: Dalon L Westergreen <[email protected]> Acked-by: Thor Thayer <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6334665 commit 6571ebc

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/net/ethernet/altera/altera_msgdma.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ u32 msgdma_tx_completions(struct altera_tse_private *priv)
145145
& 0xffff;
146146

147147
if (inuse) { /* Tx FIFO is not empty */
148-
ready = priv->tx_prod - priv->tx_cons - inuse - 1;
148+
ready = max_t(int,
149+
priv->tx_prod - priv->tx_cons - inuse - 1, 0);
149150
} else {
150151
/* Check for buffered last packet */
151152
status = csrrd32(priv->tx_dma_csr, msgdma_csroffs(status));

0 commit comments

Comments
 (0)