diff mbox

[API-NEXT,v2,9/9] queue: handle return value of odp_queue_enq_multi()

Message ID 1433505231-28843-10-git-send-email-zoltan.kiss@linaro.org
State New
Headers show

Commit Message

Zoltan Kiss June 5, 2015, 11:53 a.m. UTC
Unsent packet has to be released. If the event type is obvious from the
context, use directly the relevant release functions, otherwise
odp_event(free).
Wider error handling is attempted, but this patch can't fix all the flaws
in the many calling functions of odp_queue_enq()

Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
---
 test/performance/odp_pktio_perf.c | 15 ++++++++++++++-
 test/performance/odp_scheduling.c | 10 ++++++++--
 test/validation/odp_pktio.c       |  5 +++++
 test/validation/odp_queue.c       |  6 ++++++
 4 files changed, 33 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
index f572633..4bef389 100644
--- a/test/performance/odp_pktio_perf.c
+++ b/test/performance/odp_pktio_perf.c
@@ -268,6 +268,9 @@  static int alloc_packets(odp_event_t *event_tbl, int num_pkts)
 static int send_packets(odp_queue_t outq,
 			odp_event_t *event_tbl, unsigned num_pkts)
 {
+	int ret;
+	unsigned cnt;
+
 	if (num_pkts == 0)
 		return 0;
 	else if (num_pkts == 1) {
@@ -279,7 +282,17 @@  static int send_packets(odp_queue_t outq,
 		}
 	}
 
-	return odp_queue_enq_multi(outq, event_tbl, num_pkts);
+	ret = odp_queue_enq_multi(outq, event_tbl, num_pkts);
+	if (ret == (signed)num_pkts)
+		return ret;
+
+	if (ret < 0)
+		ret = 0;
+	cnt = ret;
+	do
+		odp_event_free(event_tbl[cnt]);
+	while (++cnt < num_pkts);
+	return ret;
 }
 
 /*
diff --git a/test/performance/odp_scheduling.c b/test/performance/odp_scheduling.c
index 1283986..8b46eb2 100644
--- a/test/performance/odp_scheduling.c
+++ b/test/performance/odp_scheduling.c
@@ -535,9 +535,15 @@  static int test_schedule_multi(const char *str, int thr,
 		}
 
 		/* Assume we can enqueue all events */
-		if (odp_queue_enq_multi(queue, ev, MULTI_BUFS_MAX) !=
-		    MULTI_BUFS_MAX) {
+		j = odp_queue_enq_multi(queue, ev, MULTI_BUFS_MAX);
+		if (j != MULTI_BUFS_MAX) {
 			LOG_ERR("  [%i] Queue enqueue failed.\n", thr);
+			if (j < 0)
+				j = 0;
+			do
+				odp_event_free(ev[j]);
+			while (++j < MULTI_BUFS_MAX);
+
 			return -1;
 		}
 	}
diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c
index 3027b25..d25e5fa 100644
--- a/test/validation/odp_pktio.c
+++ b/test/validation/odp_pktio.c
@@ -387,6 +387,11 @@  static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b,
 		ret = odp_queue_enq_multi(pktio_a->outq, tx_ev, num_pkts);
 		if (ret != num_pkts) {
 			CU_FAIL("failed to enqueue test packets");
+			if (ret < 0)
+				ret = 0;
+			do
+				odp_packet_free(tx_pkt[ret]);
+			while (++ret < num_pkts);
 			return;
 		}
 	}
diff --git a/test/validation/odp_queue.c b/test/validation/odp_queue.c
index 4bd95ff..9d01f45 100644
--- a/test/validation/odp_queue.c
+++ b/test/validation/odp_queue.c
@@ -96,6 +96,12 @@  static void test_odp_queue_sunnyday(void)
 	 */
 	ret = odp_queue_enq_multi(queue_id, enev, MAX_BUFFER_QUEUE);
 	CU_ASSERT(MAX_BUFFER_QUEUE == ret);
+	if (ret < 0)
+		ret = 0;
+	do
+		odp_event_free(enev[ret]);
+	while (++ret < MAX_BUFFER_QUEUE);
+
 	pev_tmp = deev;
 	do {
 		deq_ret  = odp_queue_deq_multi(queue_id, pev_tmp,