diff mbox

linux-generic: check return codes in odp_pktio_term_global

Message ID 1446197249-20852-1-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Oct. 30, 2015, 9:27 a.m. UTC
According to API odp_pktio_close() can be called only for stopped
pktio. So in odp_pktio_term_global try to stop it first then
call close. Also check all returns codes.
https://bugs.linaro.org/show_bug.cgi?id=1854

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_packet_io.c | 57 +++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 21 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 1246bff..feae796 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -30,6 +30,21 @@  static pktio_table_t *pktio_tbl;
 /* pktio pointer entries ( for inlines) */
 void *pktio_entry_ptr[ODP_CONFIG_PKTIO_ENTRIES];
 
+static int is_free(pktio_entry_t *entry)
+{
+	return (entry->s.taken == 0);
+}
+
+static void set_free(pktio_entry_t *entry)
+{
+	entry->s.taken = 0;
+}
+
+static void set_taken(pktio_entry_t *entry)
+{
+	entry->s.taken = 1;
+}
+
 int odp_pktio_init_global(void)
 {
 	char name[ODP_QUEUE_NAME_LEN];
@@ -91,17 +106,32 @@  int odp_pktio_term_global(void)
 	int id;
 	int pktio_if;
 
-	for (id = 1; id <= ODP_CONFIG_PKTIO_ENTRIES; ++id) {
-		pktio_entry = &pktio_tbl->entries[id - 1];
-		odp_pktio_close(pktio_entry->s.handle);
-		odp_queue_destroy(pktio_entry->s.outq_default);
+	for (id = 0; id < ODP_CONFIG_PKTIO_ENTRIES; ++id) {
+		pktio_entry = &pktio_tbl->entries[id];
+
+		ret = odp_queue_destroy(pktio_entry->s.outq_default);
+		if (ret)
+			ODP_ABORT("unable to destroy outq %s\n",
+				  pktio_entry->s.name);
+		if (is_free(pktio_entry))
+			continue;
+		if (pktio_entry->s.state != STATE_STOP) {
+			ret = odp_pktio_stop(pktio_entry->s.handle);
+			if (ret)
+				ODP_ABORT("unable to stop pktio %s\n",
+					  pktio_entry->s.name);
+		}
+		ret = odp_pktio_close(pktio_entry->s.handle);
+		if (ret)
+			ODP_ABORT("unable to close pktio %s\n",
+				  pktio_entry->s.name);
 	}
 
 	for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) {
 		if (pktio_if_ops[pktio_if]->term)
 			if (pktio_if_ops[pktio_if]->term())
-				ODP_ERR("failed to terminate pktio type %d",
-					pktio_if);
+				ODP_ABORT("failed to terminate pktio type %d",
+					  pktio_if);
 	}
 
 	ret = odp_shm_free(odp_shm_lookup("odp_pktio_entries"));
@@ -116,21 +146,6 @@  int odp_pktio_init_local(void)
 	return 0;
 }
 
-static int is_free(pktio_entry_t *entry)
-{
-	return (entry->s.taken == 0);
-}
-
-static void set_free(pktio_entry_t *entry)
-{
-	entry->s.taken = 0;
-}
-
-static void set_taken(pktio_entry_t *entry)
-{
-	entry->s.taken = 1;
-}
-
 static void lock_entry(pktio_entry_t *entry)
 {
 	odp_ticketlock_lock(&entry->s.lock);