From 25cad6ffcfe59a2801bdabcc72154d57a30e3a26 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 7 Dec 2015 16:48:25 -0700 Subject: [PATCH] ioat: clean up on exit in examples Previously, the cleanup functions were only being called if there was an error during initialization. Change-Id: I1606cfa9a9c3732d670131f78249d34a5db47403 Signed-off-by: Daniel Verkamp --- examples/ioat/perf/perf.c | 18 ++++++++++++++---- examples/ioat/verify/verify.c | 21 +++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/examples/ioat/perf/perf.c b/examples/ioat/perf/perf.c index b09d48ffd..36cf528bf 100644 --- a/examples/ioat/perf/perf.c +++ b/examples/ioat/perf/perf.c @@ -112,7 +112,9 @@ ioat_exit(void) while (!TAILQ_EMPTY(&g_devices)) { dev = TAILQ_FIRST(&g_devices); TAILQ_REMOVE(&g_devices, dev, tailq); - ioat_detach(dev->ioat); + if (dev->ioat) { + ioat_detach(dev->ioat); + } rte_free(dev); } } @@ -406,6 +408,7 @@ main(int argc, char **argv) { unsigned lcore_id; struct thread_entry threads[RTE_MAX_LCORE] = {}; + int rc; if (parse_args(argc, argv) != 0) { return 1; @@ -422,14 +425,21 @@ main(int argc, char **argv) } if (work_fn(&threads[rte_get_master_lcore()]) != 0) { - return 1; + rc = 1; + goto cleanup; } RTE_LCORE_FOREACH_SLAVE(lcore_id) { if (rte_eal_wait_lcore(lcore_id) != 0) { - return 1; + rc = 1; + goto cleanup; } } - return dump_result(threads, RTE_MAX_LCORE); + rc = dump_result(threads, RTE_MAX_LCORE); + +cleanup: + ioat_exit(); + + return rc; } diff --git a/examples/ioat/verify/verify.c b/examples/ioat/verify/verify.c index 05682b86e..a8e82643f 100644 --- a/examples/ioat/verify/verify.c +++ b/examples/ioat/verify/verify.c @@ -113,8 +113,10 @@ ioat_exit(void) while (!TAILQ_EMPTY(&g_devices)) { dev = TAILQ_FIRST(&g_devices); TAILQ_REMOVE(&g_devices, dev, tailq); - ioat_detach(dev->ioat); - rte_free(dev); + if (dev->ioat) { + ioat_detach(dev->ioat); + } + free(dev); } } static void prepare_ioat_task(struct thread_entry *thread_entry, struct ioat_task *ioat_task) @@ -408,6 +410,7 @@ main(int argc, char **argv) { unsigned lcore_id; struct thread_entry threads[RTE_MAX_LCORE] = {}; + int rc; if (parse_args(argc, argv) != 0) { return 1; @@ -424,16 +427,22 @@ main(int argc, char **argv) } if (work_fn(&threads[rte_get_master_lcore()]) != 0) { - return 1; + rc = 1; + goto cleanup; } RTE_LCORE_FOREACH_SLAVE(lcore_id) { if (rte_eal_wait_lcore(lcore_id) != 0) { - return 1; + rc = 1; + goto cleanup; } } - rte_free(g_src); + rc = dump_result(threads, RTE_MAX_LCORE); - return dump_result(threads, RTE_MAX_LCORE); +cleanup: + rte_free(g_src); + ioat_exit(); + + return rc; }