diff options
author | Michael Chan <mchan@broadcom.com> | 2006-12-14 18:56:32 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-18 00:59:15 -0500 |
commit | faac9c4b753f420c02bdce0785d2657087830a12 (patch) | |
tree | b9f6aee28676bb22e1c4c12197797242024c03fa /drivers | |
parent | a3d384029aa304f8f3f5355d35f0ae274454f7cd (diff) |
[BNX2]: Fix panic in bnx2_tx_int().
There was an off-by-one bug in bnx2_tx_avail(). If the tx ring is
completely full, the producer and consumer indices may be apart by
256 even though the ring size is only 255. One entry in the ring is
unused and must be properly accounted for when calculating the number
of available entries. The bug caused the tx ring entries to be
reused by mistake, overwriting active entries, and ultimately causing
it to crash.
This bug rarely occurs because the tx ring is rarely completely full.
We always stop when there is less than MAX_SKB_FRAGS entries available
in the ring.
Thanks to Corey Kovacs <cjk@techma.com> and Andy Gospodarek
<agospoda@redhat.com> for reporting the problem and helping to collect
debug information.
Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/bnx2.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c index 7d824cf8ee2d..f296c37f29b6 100644 --- a/drivers/net/bnx2.c +++ b/drivers/net/bnx2.c | |||
@@ -217,9 +217,16 @@ static inline u32 bnx2_tx_avail(struct bnx2 *bp) | |||
217 | u32 diff; | 217 | u32 diff; |
218 | 218 | ||
219 | smp_mb(); | 219 | smp_mb(); |
220 | diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons); | 220 | |
221 | if (diff > MAX_TX_DESC_CNT) | 221 | /* The ring uses 256 indices for 255 entries, one of them |
222 | diff = (diff & MAX_TX_DESC_CNT) - 1; | 222 | * needs to be skipped. |
223 | */ | ||
224 | diff = bp->tx_prod - bp->tx_cons; | ||
225 | if (unlikely(diff >= TX_DESC_CNT)) { | ||
226 | diff &= 0xffff; | ||
227 | if (diff == TX_DESC_CNT) | ||
228 | diff = MAX_TX_DESC_CNT; | ||
229 | } | ||
223 | return (bp->tx_ring_size - diff); | 230 | return (bp->tx_ring_size - diff); |
224 | } | 231 | } |
225 | 232 | ||