diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-01-15 20:17:09 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-01-15 20:17:09 +0000 |
commit | b030cebf0d81c584e0f34a6804447bceeee5f401 (patch) | |
tree | b00886c26ba62bfcaf9d15ef503121d2129647a1 /sys/dev/pci/if_bwfm_pci.c | |
parent | d905a43a1ec87eae5e40bfcd1e1f5c4555efd2b6 (diff) |
Fix off-by-one in ringbuffer code. When we insert items faster than
the hardware is processing them, the write index can catch up to the
read index. We must make sure that our write index stays smaller
than the hardware's read index, thus the difference between both has
to be bigger than 1.
ok tobhe@
Diffstat (limited to 'sys/dev/pci/if_bwfm_pci.c')
-rw-r--r-- | sys/dev/pci/if_bwfm_pci.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/dev/pci/if_bwfm_pci.c b/sys/dev/pci/if_bwfm_pci.c index 16fc305957a..ba9652b8a42 100644 --- a/sys/dev/pci/if_bwfm_pci.c +++ b/sys/dev/pci/if_bwfm_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bwfm_pci.c,v 1.30 2020/01/09 14:35:19 mpi Exp $ */ +/* $OpenBSD: if_bwfm_pci.c,v 1.31 2020/01/15 20:17:08 patrick Exp $ */ /* * Copyright (c) 2010-2016 Broadcom Corporation * Copyright (c) 2017 Patrick Wildt <patrick@blueri.se> @@ -1150,7 +1150,7 @@ bwfm_pci_ring_write_reserve(struct bwfm_pci_softc *sc, else available = ring->r_ptr + (ring->nitem - ring->w_ptr); - if (available < 1) + if (available <= 1) return NULL; ret = BWFM_PCI_DMA_KVA(ring->ring) + (ring->w_ptr * ring->itemsz); @@ -1174,7 +1174,7 @@ bwfm_pci_ring_write_reserve_multi(struct bwfm_pci_softc *sc, else available = ring->r_ptr + (ring->nitem - ring->w_ptr); - if (available < 1) + if (available <= 1) return NULL; ret = BWFM_PCI_DMA_KVA(ring->ring) + (ring->w_ptr * ring->itemsz); |