DPDK patches and discussions
 help / color / mirror / Atom feed
From: Muhammad Bilal <m.bilal@emumba.com>
To: declan.doherty@intel.com, tomasz.kantecki@intel.com,
	pbhagavatula@marvell.com, skori@marvell.com
Cc: dev@dpdk.org, Muhammad Bilal <m.bilal@emumba.com>
Subject: [dpdk-dev] [PATCH 4/5] examples/l2fwd-cat: free resources in case of error
Date: Tue, 19 May 2020 13:54:43 +0500	[thread overview]
Message-ID: <20200519085444.4562-4-m.bilal@emumba.com> (raw)
In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com>

Freeing the resources and call rte_eal_cleanup in case of error exit.
Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
---
 examples/l2fwd-cat/l2fwd-cat.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/examples/l2fwd-cat/l2fwd-cat.c b/examples/l2fwd-cat/l2fwd-cat.c
index 45a497c08..06eeae9ae 100644
--- a/examples/l2fwd-cat/l2fwd-cat.c
+++ b/examples/l2fwd-cat/l2fwd-cat.c
@@ -147,6 +147,18 @@ lcore_main(void)
 	}
 }
 
+static void
+stop_and_close_eth_dev(uint16_t portid)
+{
+	RTE_ETH_FOREACH_DEV(portid) {
+		printf("Closing port %d...", portid);
+		rte_eth_dev_stop(portid);
+		rte_eth_dev_close(portid);
+		printf(" Done\n");
+	}
+	rte_eal_cleanup();
+}
+
 /*
  * The main function, which does initialization and calls the per-lcore
  * functions.
@@ -156,7 +168,7 @@ main(int argc, char *argv[])
 {
 	struct rte_mempool *mbuf_pool;
 	unsigned nb_ports;
-	uint16_t portid;
+	uint16_t portid = 0;
 
 	/* Initialize the Environment Abstraction Layer (EAL). */
 	int ret = rte_eal_init(argc, argv);
@@ -171,30 +183,38 @@ main(int argc, char *argv[])
 	 * Please see l2fwd-cat documentation for more info.
 	 */
 	ret = cat_init(argc, argv);
-	if (ret < 0)
+	if (ret < 0) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "PQOS: L3CA init failed!\n");
+	}
 
 	argc -= ret;
 	argv += ret;
 
 	/* Check that there is an even number of ports to send/receive on. */
 	nb_ports = rte_eth_dev_count_avail();
-	if (nb_ports < 2 || (nb_ports & 1))
+	if (nb_ports < 2 || (nb_ports & 1)) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");
+	}
 
 	/* Creates a new mempool in memory to hold the mbufs. */
 	mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
 		MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
 
-	if (mbuf_pool == NULL)
+	if (mbuf_pool == NULL) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
+	}
 
 	/* Initialize all ports. */
 	RTE_ETH_FOREACH_DEV(portid)
-		if (port_init(portid, mbuf_pool) != 0)
+		if (port_init(portid, mbuf_pool) != 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu16 "\n",
 					portid);
-
+		}
+
 	if (rte_lcore_count() > 1)
 		printf("\nWARNING: Too many lcores enabled. Only 1 used.\n");
 
-- 
2.17.1


  parent reply	other threads:[~2020-05-19  8:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19  8:54 [dpdk-dev] [PATCH 1/5] examples/l2fwd-event: " Muhammad Bilal
2020-05-19  8:54 ` [dpdk-dev] [PATCH 2/5] examples/l2fwd-jobstats: " Muhammad Bilal
2020-05-19  8:54 ` [dpdk-dev] [PATCH 3/5] examples/l2fwd-keepalive: " Muhammad Bilal
2020-05-19  8:54 ` Muhammad Bilal [this message]
2020-05-19  8:54 ` [dpdk-dev] [PATCH 5/5] examples/l2fwd-crypto: " Muhammad Bilal
2020-05-19  9:34 ` [dpdk-dev] [EXT] [PATCH 1/5] examples/l2fwd-event: " Sunil Kumar Kori
2020-06-02 12:27   ` Muhammad Bilal
2020-06-10 10:01     ` Sunil Kumar Kori
2020-06-15 12:00       ` Muhammad Bilal
2020-06-16  5:53         ` Sunil Kumar Kori
2020-06-16 10:14           ` Muhammad Bilal
2020-06-16 10:38             ` Sunil Kumar Kori
2023-06-12 16:56               ` Stephen Hemminger
2023-06-12 17:17                 ` Sunil Kumar Kori
2020-06-16 11:47       ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200519085444.4562-4-m.bilal@emumba.com \
    --to=m.bilal@emumba.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=pbhagavatula@marvell.com \
    --cc=skori@marvell.com \
    --cc=tomasz.kantecki@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).