From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3824EA0093; Tue, 19 May 2020 10:55:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 62F781D5DA; Tue, 19 May 2020 10:55:35 +0200 (CEST) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by dpdk.org (Postfix) with ESMTP id EC62E1D5D8 for ; Tue, 19 May 2020 10:55:32 +0200 (CEST) Received: by mail-wm1-f68.google.com with SMTP id n18so2515979wmj.5 for ; Tue, 19 May 2020 01:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z6A1A6TDLHKnvHPlWFTMsJIBwCeFb8WRShYXw6xTz/M=; b=jzCZni7zhUVfRSUQW8bcsieuIBggtQZEm/7Ikt8zethmv6L1tMiI8MRXhiSUI4UcyG aK6dKD7dwEvmH8mQgDr8A7XgewB5V/bOI6upJMTo/qZ9VvUrMAtgnvPXt6o0uEijrdmQ 39BLIcFYYWigWuDNmYVLJVxgaVXnVHxLqVgu0tRRMZAh/YzL3hNmWe3TTDWDfThR42IF gAgcdR6LvZF5ibiNQ0OohR1ers0AKaOXIVpZN+iywhP5vKs7jrV/NZ7cb/CipKdl5wyz XzJJ3hmiynbt56N4vqlAj8P6tZcY+f61sI1sS23L3qaeJrc4UOWTfK6QLP+6rGaldgdn cbzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z6A1A6TDLHKnvHPlWFTMsJIBwCeFb8WRShYXw6xTz/M=; b=hoZSiNs7695CpLV4jOOIWZ+EeYVakZT0dSuiyObZE7pMlihLOcAXE21mQXN18LO4vr VggYzrQWO84Zt8RcgPWeV1k8aOypJUM8EJCSAMoDMyv/rZHzmWAMR7rU7CkG+EhkWkVq 53bBQ0jXvCdDkkEMXX3BI5JM8xKcICQ43wTZ4+CMwwd7+NCEunXXV5XyXOS5DghrmE3+ IGY8pzA63ct+JLr2zD0tuQOnBbSFLshwL14z/R29rKAZYjec8w1Es76uzJHEMXS4l2em WLm4n0kC+m+D+1vA3RA4a5Wz4sjKzuYnFfQmMtBMGMlRcg1cC+klDN+sZHlYrteFtag1 w1kg== X-Gm-Message-State: AOAM531UYGYYx17pytFcKGbnrJlPCJQerkQnPhl5K2+nuXzah4UckOdw 7V5tmk7jGbOAOzhemYEm89EjkA== X-Google-Smtp-Source: ABdhPJztgheHlkeKyCYv0TYoyZvhQ5//cg9lHVod2xPeIAfqsBsEBq/24ht/qF9kaLPOmkOQmVMPRw== X-Received: by 2002:a1c:3585:: with SMTP id c127mr4182584wma.34.1589878532650; Tue, 19 May 2020 01:55:32 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:32 -0700 (PDT) From: Muhammad Bilal To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal Date: Tue, 19 May 2020 13:54:43 +0500 Message-Id: <20200519085444.4562-4-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com> References: <20200519085444.4562-1-m.bilal@emumba.com> Subject: [dpdk-dev] [PATCH 4/5] examples/l2fwd-cat: free resources in case of error X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Freeing the resources and call rte_eal_cleanup in case of error exit. Signed-off-by: Muhammad Bilal --- 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