DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Anatoly Burakov <anatoly.burakov@intel.com>,
	Qi Zhang <qi.z.zhang@intel.com>
Subject: [PATCH v2] examples/multi_process: check return value from get name
Date: Sun, 22 Nov 2026 09:35:20 -0800	[thread overview]
Message-ID: <20261122173556.105738-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20261120191326.4052618-1-stephen@networkplumber.org>

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")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v2 - fix printf format typo, and commit message

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

diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c
index e84e130b3c..7179a5bf8e 100644
--- a/examples/multi_process/hotplug_mp/commands.c
+++ b/examples/multi_process/hotplug_mp/commands.c
@@ -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));
 	}
 }
 
-- 
2.53.0


  reply	other threads:[~2026-11-22 17:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 19:13 [PATCH] examples/multi_process: check return value from get name Stephen Hemminger
2026-11-22 17:35 ` Stephen Hemminger [this message]
2026-11-23  8:52   ` [PATCH v2] " Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122173556.105738-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox