From: Tetsuya Mukawa Date: Fri, 27 Feb 2015 07:16:15 +0000 (+0900) Subject: app/testpmd: fix crash when portmask is specified X-Git-Tag: spdx-start~9515 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=ffc468ff3cfe768b0132f851cef6382cd16a3c68;p=dpdk.git app/testpmd: fix crash when portmask is specified If testpmd is invoked with portmask option like below, segmentation fault will occur. This patch fixes the issue. Reported-by: Pablo de Lara Signed-off-by: Tetsuya Mukawa Acked-by: Pablo de Lara --- diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 43329ed796..61291be078 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -579,20 +579,6 @@ init_config(void) socket_num); } - /* Configuration of Ethernet ports. */ - ports = rte_zmalloc("testpmd: ports", - sizeof(struct rte_port) * RTE_MAX_ETHPORTS, - RTE_CACHE_LINE_SIZE); - if (ports == NULL) { - rte_exit(EXIT_FAILURE, - "rte_zmalloc(%d struct rte_port) failed\n", - RTE_MAX_ETHPORTS); - } - - /* enabled allocated ports */ - for (pid = 0; pid < nb_ports; pid++) - ports[pid].enabled = 1; - FOREACH_PORT(pid, ports) { port = &ports[pid]; rte_eth_dev_info_get(pid, &port->dev_info); @@ -1999,6 +1985,26 @@ init_port_dcb_config(portid_t pid,struct dcb_config *dcb_conf) return 0; } +static void +init_port(void) +{ + portid_t pid; + + /* Configuration of Ethernet ports. */ + ports = rte_zmalloc("testpmd: ports", + sizeof(struct rte_port) * RTE_MAX_ETHPORTS, + RTE_CACHE_LINE_SIZE); + if (ports == NULL) { + rte_exit(EXIT_FAILURE, + "rte_zmalloc(%d struct rte_port) failed\n", + RTE_MAX_ETHPORTS); + } + + /* enabled allocated ports */ + for (pid = 0; pid < nb_ports; pid++) + ports[pid].enabled = 1; +} + int main(int argc, char** argv) { @@ -2013,6 +2019,9 @@ main(int argc, char** argv) if (nb_ports == 0) RTE_LOG(WARNING, EAL, "No probed ethernet devices\n"); + /* allocate port structures, and init them */ + init_port(); + set_def_fwd_config(); if (nb_lcores == 0) rte_panic("Empty set of forwarding logical cores - check the "