Skip to contentSkip to conversation

examples/multi_process: check return value from get name

PATCH Superseded Stephen Hemminger 2 participants 3 messages Nov 20 – Nov 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/multi_process: check return value from get name

Better to use the return value of rte_eth_dev_get_name_by_port() rather than depending on side effect of name being set or not.

Coverity ID: 511674

---
 examples/multi_process/hotplug_mp/commands.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
examples/multi_process/hotplug_mp/commands.c +6 -5
index e84e130b3c..b4cd073a4b 100644
@@ -35,13 +35,14 @@ cmd_list_parsed(__rte_unused void *parsed_result,
 	cmdline_printf(cl, "list all etherdev\n");
 
 	RTE_ETH_FOREACH_DEV(port_id) {
-		char dev_name[RTE_DEV_NAME_MAX_LEN] = "";
+		char dev_name[RTE_DEV_NAME_MAX_LEN];
+		int ret;
 
-		rte_eth_dev_get_name_by_port(port_id, dev_name, sizeof(dev_name));
-		if (strlen(dev_name) > 0)
-			cmdline_printf(cl, "%d\t%s\n", port_id, dev_name);
+		ret = rte_eth_dev_get_name_by_port(port_id, dev_name, sizeof(dev_name));
+		if (ret == 0)
+			cmdline_printf(cl, "%u\t%s\n", port_id, dev_name);
 		else
-			printf("empty dev_name is not expected!\n");
+			cmdline_printf(cl, "%u\error - %s\n", port_id, strerror(-ret));
 	}
 }
 
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/1 examples/multi_process: check return value from get name

Better to use the return value of rte_eth_dev_get_name_by_port() rather than depending on side effect of name being set or not.

Coverity issue: 511674

Fixes 05f1d6842fc3 ("examples/multi_process: add hotplug sample")

---
v2 - fix printf format typo, and commit message

 examples/multi_process/hotplug_mp/commands.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
examples/multi_process/hotplug_mp/commands.c +9 -5
index e84e130b3c..7179a5bf8e 100644
@@ -2,6 +2,8 @@
  * Copyright(c) 2018-2023 Intel Corporation.
  */
 
+#include <string.h>
+
 #include <rte_bus.h>
 #include <rte_ethdev.h>
 #include "commands.h"
@@ -35,13 +37,15 @@ cmd_list_parsed(__rte_unused void *parsed_result,
 	cmdline_printf(cl, "list all etherdev\n");
 
 	RTE_ETH_FOREACH_DEV(port_id) {
-		char dev_name[RTE_DEV_NAME_MAX_LEN] = "";
+		char dev_name[RTE_DEV_NAME_MAX_LEN];
+		int ret;
 
-		rte_eth_dev_get_name_by_port(port_id, dev_name, sizeof(dev_name));
-		if (strlen(dev_name) > 0)
-			cmdline_printf(cl, "%d\t%s\n", port_id, dev_name);
+		ret = rte_eth_dev_get_name_by_port(port_id, dev_name, sizeof(dev_name));
+		if (ret == 0)
+			cmdline_printf(cl, "%u\t%s\n", port_id, dev_name);
 		else
-			printf("empty dev_name is not expected!\n");
+			cmdline_printf(cl, "No name for port %u: %s\n",
+				       port_id, strerror(-ret));
 	}
 }
 
Signature · 1 line
2.53.0
Acked-by on v2 1/1
#2 lore raw
Quoted 4 lines · Stephen Hemminger

Better to use the return value of rte_eth_dev_get_name_by_port() rather than depending on side effect of name being set or not.

Coverity issue: 511674

Quoted 9 lines
Fixes 05f1d6842fc3 ("examples/multi_process: add hotplug sample")

---
v2 - fix printf format typo, and commit message

 examples/multi_process/hotplug_mp/commands.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Don't think this needs to go in 26.11, but LGTM for 27.03 merge.

/Bruce