[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 34/56] fifo8: add skip parameter to fifo8_peekpop_bufptr()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 34/56] fifo8: add skip parameter to fifo8_peekpop_bufptr() |
Date: |
Wed, 11 Sep 2024 14:13:59 +0200 |
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
The skip parameter specifies the number of bytes to be skipped
from the current FIFO head before the peek or pop operation.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Octavian Purdila <tavip@google.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20240828122258.928947-4-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
util/fifo8.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/util/fifo8.c b/util/fifo8.c
index 5faa814a6e..62d6430b05 100644
--- a/util/fifo8.c
+++ b/util/fifo8.c
@@ -72,18 +72,20 @@ uint8_t fifo8_pop(Fifo8 *fifo)
}
static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
- uint32_t *numptr, bool do_pop)
+ uint32_t skip, uint32_t *numptr,
+ bool do_pop)
{
uint8_t *ret;
uint32_t num, head;
assert(max > 0 && max <= fifo->num);
- head = fifo->head;
+ assert(skip <= fifo->num);
+ head = (fifo->head + skip) % fifo->capacity;
num = MIN(fifo->capacity - head, max);
ret = &fifo->data[head];
if (do_pop) {
- fifo->head += num;
+ fifo->head = head + num;
fifo->head %= fifo->capacity;
fifo->num -= num;
}
@@ -95,12 +97,12 @@ static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo,
uint32_t max,
const uint8_t *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr)
{
- return fifo8_peekpop_bufptr(fifo, max, numptr, false);
+ return fifo8_peekpop_bufptr(fifo, max, 0, numptr, false);
}
const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr)
{
- return fifo8_peekpop_bufptr(fifo, max, numptr, true);
+ return fifo8_peekpop_bufptr(fifo, max, 0, numptr, true);
}
uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen)
--
2.45.2
- [PULL 22/56] hw/audio/virtio-sound: fix heap buffer overflow, (continued)
- [PULL 22/56] hw/audio/virtio-sound: fix heap buffer overflow, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 19/56] target/cris: Remove the deprecated CRIS target, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 25/56] hw/char/pl011: Move pl011_loopback_enabled|tx() around, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 24/56] hw/char/pl011: Move pl011_put_fifo() earlier, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 21/56] target/riscv: Remove the deprecated 'any' CPU type, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 31/56] MAINTAINERS: Add myself as a reviewer of VT-d, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 30/56] hw/char/pl011: Rename RX FIFO methods, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 32/56] fifo8: rename fifo8_peekpop_buf() to fifo8_peekpop_bufptr(), Philippe Mathieu-Daudé, 2024/09/11
- [PULL 20/56] seccomp: Remove check for CRIS host, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 29/56] hw/char/pl011: Warn when using disabled transmitter, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 34/56] fifo8: add skip parameter to fifo8_peekpop_bufptr(),
Philippe Mathieu-Daudé <=
- [PULL 23/56] hw/char/pl011: Remove unused 'readbuff' field, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 26/56] hw/char/pl011: Split RX/TX path of pl011_reset_fifo(), Philippe Mathieu-Daudé, 2024/09/11
- [PULL 27/56] hw/char/pl011: Extract pl011_write_txdata() from pl011_write(), Philippe Mathieu-Daudé, 2024/09/11
- [PULL 33/56] fifo8: introduce head variable for fifo8_peekpop_bufptr(), Philippe Mathieu-Daudé, 2024/09/11
- [PULL 28/56] hw/char/pl011: Extract pl011_read_rxdata() from pl011_read(), Philippe Mathieu-Daudé, 2024/09/11
- [PULL 38/56] fifo8: add fifo8_peek_buf() function, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 36/56] fifo8: rename fifo8_pop_buf() to fifo8_peekpop_buf(), Philippe Mathieu-Daudé, 2024/09/11
- [PULL 42/56] tests/unit: Expand test_fifo8_peek_buf_wrap() coverage, Philippe Mathieu-Daudé, 2024/09/11
- [PULL 37/56] fifo8: honour do_pop argument in fifo8_peekpop_buf(), Philippe Mathieu-Daudé, 2024/09/11
- [PULL 39/56] fifo8: introduce fifo8_peek() function, Philippe Mathieu-Daudé, 2024/09/11