libmemif: fix memif_refill_queue 28/30928/2
authorJakub Grajciar <jgrajcia@cisco.com>
Tue, 26 Jan 2021 06:38:30 +0000 (07:38 +0100)
committerDamjan Marion <dmarion@me.com>
Fri, 5 Feb 2021 16:20:52 +0000 (16:20 +0000)
Fix arithmetic error in memif_refill_queue., where
some of the buffers didn't get properly refilled.

Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I9815a8ac9b899216581452c352e75e2a0454cbce

extras/libmemif/src/main.c

index 0644f94..0c52169 100644 (file)
@@ -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 */
 }