examples/multi_process: check return value from get name
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
Signed-off-by Stephen Hemminger <[email protected]>
--- examples/multi_process/hotplug_mp/commands.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
examples/multi_process/hotplug_mp/commands.c +6 -5
@@ -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
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")
Signed-off-by Stephen Hemminger <[email protected]>
---
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
@@ -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
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")Signed-off-by Stephen Hemminger <[email protected]>---
v2 - fix printf format typo, and commit messageexamples/multi_process/hotplug_mp/commands.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
Acked-by Bruce Richardson <[email protected]>
Don't think this needs to go in 26.11, but LGTM for 27.03 merge.
/Bruce