aboutsummaryrefslogtreecommitdiffstats
path: root/extras/libmemif/src
diff options
context:
space:
mode:
authormbly <mbly@ciena.com>2023-12-06 12:22:14 -0800
committerDave Wallace <dwallacelf@gmail.com>2024-01-12 03:22:30 +0000
commit00e9fe6ca771bfbe7ee62e80a44903ffb227cae2 (patch)
tree7e831e35240435a058a431d175ece17306339b5e /extras/libmemif/src
parenta90877982011966740ddba106ef7bd624ecea6c1 (diff)
libmemif: fix for memif_init_queues slot math
Increase slot variable to u32 to address combinations of num-queues and queue-size that cause slot variable to wrap when declared as u16, e.g. num-queues > 8 && queue-size is 2^12 Type: fix Change-Id: I5bd6198d60395156a06f1a280ea2594824ceaa9d Signed-off-by: mbly <mbly@ciena.com>
Diffstat (limited to 'extras/libmemif/src')
-rw-r--r--extras/libmemif/src/main.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index cb07bf6eb2f..6f9ba2fe229 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -1258,6 +1258,7 @@ memif_init_queues (memif_connection_t *conn)
int i, j;
memif_ring_t *ring;
memif_socket_t *ms = (memif_socket_t *) conn->args.socket;
+ uint32_t ring_size = 1 << conn->run_args.log2_ring_size;
for (i = 0; i < conn->run_args.num_s2m_rings; i++)
{
@@ -1266,9 +1267,11 @@ memif_init_queues (memif_connection_t *conn)
ring->head = ring->tail = 0;
ring->cookie = MEMIF_COOKIE;
ring->flags = 0;
- for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++)
+ uint32_t base = i;
+ uint32_t ring_offset = base * ring_size;
+ for (j = 0; j < ring_size; j++)
{
- uint16_t slot = i * (1 << conn->run_args.log2_ring_size) + j;
+ uint32_t slot = ring_offset + j;
ring->desc[j].region = 1;
ring->desc[j].offset =
conn->regions[1].buffer_offset +
@@ -1283,10 +1286,11 @@ memif_init_queues (memif_connection_t *conn)
ring->head = ring->tail = 0;
ring->cookie = MEMIF_COOKIE;
ring->flags = 0;
- for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++)
+ uint32_t base = conn->run_args.num_s2m_rings + i;
+ uint32_t ring_offset = base * ring_size;
+ for (j = 0; j < ring_size; j++)
{
- uint16_t slot = (i + conn->run_args.num_s2m_rings) *
- (1 << conn->run_args.log2_ring_size) + j;
+ uint32_t slot = ring_offset + j;
ring->desc[j].region = 1;
ring->desc[j].offset =
conn->regions[1].buffer_offset +