diff options
author | Jakub Grajciar <jgrajcia@cisco.com> | 2019-06-24 10:22:12 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-07-01 15:17:13 +0000 |
commit | 389c82286db6bbe7242641e3261bd920a76cd553 (patch) | |
tree | 799913701d45e5a51412932a3293f0f4320368c2 /extras/libmemif/examples | |
parent | 160c923f99c2adc103495fab1bfcefe965fe7fb8 (diff) |
libmemif: icmp-responder example buffer management fix
Type: fix
Change-Id: Ieeb763f282ee929a121585747119f458c00056ae
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Diffstat (limited to 'extras/libmemif/examples')
-rw-r--r-- | extras/libmemif/examples/icmp_responder/main.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/extras/libmemif/examples/icmp_responder/main.c b/extras/libmemif/examples/icmp_responder/main.c index 2e85d0320d5..df94da34478 100644 --- a/extras/libmemif/examples/icmp_responder/main.c +++ b/extras/libmemif/examples/icmp_responder/main.c @@ -290,7 +290,6 @@ on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid) memif_connection_t *c = &memif_connection; int err; uint16_t rx; - uint16_t fb = 0; /* receive data from shared memory buffers */ err = memif_rx_burst (c->conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &rx); c->rx_buf_num += rx; @@ -314,10 +313,14 @@ on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid) /* mark memif buffers and shared memory buffers as free */ err = memif_refill_queue (c->conn, qid, rx, 0); - c->rx_buf_num -= fb; + /* + * In this example we can assert that c->conn points to valid connection + * and 'rx <= c->rx_buf_num'. + */ + c->rx_buf_num -= rx; DBG ("freed %d buffers. %u/%u alloc/free buffers", - fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num); + rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num); icmpr_tx_burst (c->tx_qid); @@ -327,9 +330,9 @@ error: err = memif_refill_queue (c->conn, qid, rx, 0); if (err != MEMIF_ERR_SUCCESS) INFO ("memif_buffer_free: %s", memif_strerror (err)); - c->rx_buf_num -= fb; + c->rx_buf_num -= rx; DBG ("freed %d buffers. %u/%u alloc/free buffers", - fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num); + rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num); return 0; } |