From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bcmv-tmail01.ecl.ntt.co.jp (bcmv-tmail01.ecl.ntt.co.jp [124.146.185.148]) by dpdk.org (Postfix) with ESMTP id C8A921B4D3 for ; Tue, 9 Oct 2018 12:54:10 +0200 (CEST) Received: from bcmv-ns01.ecl.ntt.co.jp (bcmv-ns01.ecl.ntt.co.jp [129.60.83.123]) by bcmv-tmail01.ecl.ntt.co.jp (8.14.4/8.14.4) with ESMTP id w99As9Zt017862; Tue, 9 Oct 2018 19:54:09 +0900 Received: from bcmv-ns01.ecl.ntt.co.jp (localhost [127.0.0.1]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 9B774125; Tue, 9 Oct 2018 19:54:09 +0900 (JST) Received: from localhost.localdomain (unknown [129.60.13.51]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 8EED2119; Tue, 9 Oct 2018 19:54:09 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Tue, 9 Oct 2018 19:53:57 +0900 Message-Id: <20181009105400.42817-4-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20181009105400.42817-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20181009105400.42817-1-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 3/6] spp_vm: fix bug of do_del if port does not exist X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2018 10:54:11 -0000 From: Yasufumi Ogawa Fix bug of do_del() causing segmentation fault if not existing port is deleted. It is because determining the result of find_port_id() is incorrect and tries to delete invalid port. This update is to correct the result of find_port_id() and determining port ID. Signed-off-by: Yasufumi Ogawa --- src/vm/main.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/vm/main.c b/src/vm/main.c index 63d5684..3807370 100644 --- a/src/vm/main.c +++ b/src/vm/main.c @@ -205,11 +205,15 @@ forward_array_remove(int port_id) } } -static int +/* + * Return actual port ID which is assigned by system internally, or PORT_RESET + * if port is not found. + */ +static uint16_t find_port_id(int id, enum port_type type) { - int port_id = PORT_RESET; - unsigned int i; + uint16_t port_id = PORT_RESET; + uint16_t i; for (i = 0; i < RTE_MAX_ETHPORTS; i++) { if (port_map[i].port_type != type) @@ -227,21 +231,24 @@ find_port_id(int id, enum port_type type) static int do_del(char *res_uid) { - int port_id = PORT_RESET; + uint16_t port_id = PORT_RESET; char *p_type; int p_id; int res; res = parse_resource_uid(res_uid, &p_type, &p_id); - if (res < 0) + if (res < 0) { + RTE_LOG(ERR, APP, + "Failed to parse resource UID\n"); return -1; + } if (!strcmp(p_type, "ring")) { char name[RTE_ETH_NAME_MAX_LEN]; RTE_LOG(DEBUG, APP, "Del ring id %d\n", p_id); port_id = find_port_id(p_id, RING); - if (port_id < 0) + if (port_id == PORT_RESET) return -1; rte_eth_dev_detach(port_id, name); -- 2.7.4