util/fifo8: Introduce fifo8_drop()
authorPhilippe Mathieu-Daudé <philmd@linaro.org>
Mon, 22 Jul 2024 11:37:48 +0000 (13:37 +0200)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Tue, 23 Jul 2024 20:34:54 +0000 (22:34 +0200)
Add the fifo8_drop() helper for clarity.
It is a simple wrapper over fifo8_pop_buf().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20240722160745.67904-8-philmd@linaro.org>

hw/scsi/esp.c
include/qemu/fifo8.h
util/fifo8.c

index 04c9a557b697d7dc5899bfe983f10f97d395f28e..b7af82562323fddd93af9089a16e78b0ddf2749b 100644 (file)
@@ -351,7 +351,7 @@ static void do_message_phase(ESPState *s)
     /* Ignore extended messages for now */
     if (s->cmdfifo_cdb_offset) {
         int len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo));
-        fifo8_pop_buf(&s->cmdfifo, NULL, len);
+        fifo8_drop(&s->cmdfifo, len);
         s->cmdfifo_cdb_offset = 0;
     }
 }
index bca6da306f77806567442b9f100da416fb75c826..d1d06754d846fd739feb65cd627738b691409b8c 100644 (file)
@@ -131,6 +131,15 @@ const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr);
  */
 const uint8_t *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr);
 
+/**
+ * fifo8_drop:
+ * @fifo: FIFO to drop bytes
+ * @len: number of bytes to drop
+ *
+ * Drop (consume) bytes from a FIFO.
+ */
+void fifo8_drop(Fifo8 *fifo, uint32_t len);
+
 /**
  * fifo8_reset:
  * @fifo: FIFO to reset
index a250ea9f8046f09748b27342ef56e3f52a56e6e5..1ffa19d900ec90caf9bd76ef68b616a5cc9b53e0 100644 (file)
@@ -131,6 +131,12 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen)
     return n1 + n2;
 }
 
+void fifo8_drop(Fifo8 *fifo, uint32_t len)
+{
+    len -= fifo8_pop_buf(fifo, NULL, len);
+    assert(len == 0);
+}
+
 bool fifo8_is_empty(Fifo8 *fifo)
 {
     return (fifo->num == 0);