From 0dea94b45ad025da9289eff81e538480031d64c4 Mon Sep 17 00:00:00 2001 From: Jakub Grajciar Date: Tue, 26 Jan 2021 07:38:30 +0100 Subject: [PATCH] libmemif: fix memif_refill_queue Fix arithmetic error in memif_refill_queue., where some of the buffers didn't get properly refilled. Type: fix Signed-off-by: Jakub Grajciar Change-Id: I9815a8ac9b899216581452c352e75e2a0454cbce --- extras/libmemif/src/main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c index 0644f948c31..0c52169a155 100644 --- a/extras/libmemif/src/main.c +++ b/extras/libmemif/src/main.c @@ -2436,7 +2436,7 @@ memif_refill_queue (memif_conn_handle_t conn, uint16_t qid, uint16_t count, memif_ring_t *ring = mq->ring; uint16_t mask = (1 << mq->log2_ring_size) - 1; uint32_t offset_mask = c->run_args.buffer_size - 1; - uint16_t slot; + uint16_t slot, counter = 0; if (c->args.is_master) { @@ -2448,12 +2448,12 @@ memif_refill_queue (memif_conn_handle_t conn, uint16_t qid, uint16_t count, } uint16_t head = ring->head; + slot = head; uint16_t ns = (1 << mq->log2_ring_size) - head + mq->last_tail; - head += (count < ns) ? count : ns; + count = (count < ns) ? count : ns; - slot = ring->head; memif_desc_t *d; - while (slot < head) + while (counter < count) { d = &ring->desc[slot & mask]; d->region = 1; @@ -2463,10 +2463,11 @@ memif_refill_queue (memif_conn_handle_t conn, uint16_t qid, uint16_t count, else d->offset = d->offset - (d->offset & offset_mask) + headroom; slot++; + counter++; } MEMIF_MEMORY_BARRIER (); - ring->head = head; + ring->head = slot; return MEMIF_ERR_SUCCESS; /* 0 */ } -- 2.16.6