diff mbox

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

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

Commit Message

Zoltan Kiss June 5, 2015, 5:51 p.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(-)

Comments

Zoltan Kiss June 8, 2015, 12:50 p.m. UTC | #1
On 05/06/15 18:51, Zoltan Kiss wrote:
> diff --git a/test/validation/odp_queue.c b/test/validation/odp_queue.c
> index f8c64f7..341b702 100644
> --- a/test/validation/odp_queue.c
> +++ b/test/validation/odp_queue.c
> @@ -90,6 +90,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,

This has to be encapsulated in an "if (ret < MAX_BUFFER_QUEUE)", 
otherwise it tries to free enev[MAX_BUFFER_QUEUE].
I'll send a new version of this series, but first I would like some more 
reviews about the rest of the series.

Zoltan
diff mbox

Patch

diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
index 1ef07ae..27d0fef 100644
--- a/test/performance/odp_pktio_perf.c
+++ b/test/performance/odp_pktio_perf.c
@@ -270,6 +270,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) {
@@ -281,7 +284,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 f8c64f7..341b702 100644
--- a/test/validation/odp_queue.c
+++ b/test/validation/odp_queue.c
@@ -90,6 +90,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,