Skip to contentSkip to conversation

app/testpmd: fix crash on cleanup

PATCH Applied David Marchand 3 participants 3 messages Feb 6, 2023 – Feb 17, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: fix crash on cleanup

If allocating the ports[] array fails, a crash will occur when shutting down testpmd since ethdev emits RTE_ETH_EVENT_DESTROY events. Move init_port() before registering ethdev event handler.

Fixes 85c6571c9103 ("app/testpmd: reset port status on close notification")
---
 app/test-pmd/testpmd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
app/test-pmd/testpmd.c +3 -3
index e366f81a0f..de3017fd62 100644
@@ -4385,6 +4385,9 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
 			 rte_strerror(rte_errno));
 
+	/* allocate port structures, and init them */
+	init_port();
+
 	ret = register_eth_event_callback();
 	if (ret != 0)
 		rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");
@@ -4403,9 +4406,6 @@ main(int argc, char** argv)
 	if (nb_ports == 0)
 		TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
 
-	/* allocate port structures, and init them */
-	init_port();
-
 	set_def_fwd_config();
 	if (nb_lcores == 0)
 		rte_exit(EXIT_FAILURE, "No cores defined for forwarding\n"
Signature · 1 line
2.39.1
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · David Marchand

If allocating the ports[] array fails, a crash will occur when shutting down testpmd since ethdev emits RTE_ETH_EVENT_DESTROY events. Move init_port() before registering ethdev event handler.

Looks ok to me. Avoids seg_fault, due to Null pointer access.

Quoted 5 lines
Fixes 85c6571c9103 ("app/testpmd: reset port status on close notification")
Quoted 28 lines
---
  app/test-pmd/testpmd.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
app/test-pmd/testpmd.c +3 -3
index e366f81a0f..de3017fd62 100644
@@ -4385,6 +4385,9 @@ main(int argc, char** argv)
  		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
  			 rte_strerror(rte_errno));
 
+	/* allocate port structures, and init them */
+	init_port();
+
  	ret = register_eth_event_callback();
  	if (ret != 0)
  		rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");
@@ -4403,9 +4406,6 @@ main(int argc, char** argv)
  	if (nb_ports == 0)
  		TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
 
-	/* allocate port structures, and init them */
-	init_port();
-
  	set_def_fwd_config();
  	if (nb_lcores == 0)
  		rte_exit(EXIT_FAILURE, "No cores defined for forwarding\n"
Applied
#2 lore raw
Quoted 9 lines · Aman Deep
Quoted 3 lines · David Marchand

If allocating the ports[] array fails, a crash will occur when shutting down testpmd since ethdev emits RTE_ETH_EVENT_DESTROY events. Move init_port() before registering ethdev event handler.

Looks ok to me. Avoids seg_fault, due to Null pointer access.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Fixes 85c6571c9103 ("app/testpmd: reset port status on close

notification")
Cc: [email protected]

Applied to dpdk-next-net/main, thanks.