[PATCH v2 11/13] examples/ethtool: fix exit flag and unchecked cmdline

Stephen Hemminger stephen at networkplumber.org
Mon Sep 7 19:03:29 CEST 2026


The exit_now flag is polled by worker_main() on one lcore and set by
main() on another, but is a plain int so the load can be hoisted out
of the loop. Make it volatile.

Also check the cmdline_stdin_new() result before using it.

Found by gcc -fanalyzer.

Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
Cc: stable at dpdk.org

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
 examples/ethtool/ethtool-app/ethapp.c | 5 +++++
 examples/ethtool/ethtool-app/main.c   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/examples/ethtool/ethtool-app/ethapp.c b/examples/ethtool/ethtool-app/ethapp.c
index 489cd4f515..68c8a29b96 100644
--- a/examples/ethtool/ethtool-app/ethapp.c
+++ b/examples/ethtool/ethtool-app/ethapp.c
@@ -4,6 +4,8 @@
 
 #include <stdlib.h>
 
+#include <rte_debug.h>
+
 #include <cmdline_parse.h>
 #include <cmdline_parse_num.h>
 #include <cmdline_parse_string.h>
@@ -914,6 +916,9 @@ void ethapp_main(void)
 	struct cmdline *ctx_cmdline;
 
 	ctx_cmdline = cmdline_stdin_new(list_prompt_commands, "EthApp> ");
+	if (ctx_cmdline == NULL)
+		rte_panic("Cannot create cmdline instance\n");
+
 	cmdline_interact(ctx_cmdline);
 	cmdline_stdin_exit(ctx_cmdline);
 }
diff --git a/examples/ethtool/ethtool-app/main.c b/examples/ethtool/ethtool-app/main.c
index 6545eb322d..ddd256cd7b 100644
--- a/examples/ethtool/ethtool-app/main.c
+++ b/examples/ethtool/ethtool-app/main.c
@@ -44,7 +44,7 @@ struct app_port {
 struct app_config {
 	struct app_port ports[MAX_PORTS];
 	int cnt_ports;
-	int exit_now;
+	volatile int exit_now;
 };
 
 
-- 
2.53.0



More information about the dev mailing list