[v2] app/testpmd: fix passing negative parameter to strerror
diff mbox series

Message ID 1591326079-47091-1-git-send-email-xavier.huwei@huawei.com
State Superseded
Delegated to: Ferruh Yigit
Headers show
Series
  • [v2] app/testpmd: fix passing negative parameter to strerror
Related show

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/travis-robot success Travis build: passed
ci/iol-testing warning Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS

Commit Message

Wei Hu (Xavier) June 5, 2020, 3:01 a.m. UTC
This patch fixes them by passing '-ret' to the function strerror() when ret
is negative to fix NEGATIVE_RETURNS coverity defect warning.
Coverity issue:
  In nic_stats_clear and nic_xstats_clear function:
    Argument cannot be negative (NEGATIVE_RETURNS)
    negative_returns: ret is passed to a parameter that cannot be negative.

Fixes: da328f7f115a ("ethdev: change xstats reset function to return int")
Fixes: 9eb974221f44 ("app/testpmd: fix statistics after reset")
Cc: stable@dpdk.org

Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
---
v1 -> v2:
	1. add a negative check for ret.
	2. remove the internal coverity IDs in the commit log.
	3. update the fixed patch's commit id and titile.
---
 app/test-pmd/config.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 5381207..016bcb0 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -244,12 +244,14 @@  nic_stats_clear(portid_t port_id)
 	ret = rte_eth_stats_reset(port_id);
 	if (ret != 0) {
 		printf("%s: Error: failed to reset stats (port %u): %s",
-		       __func__, port_id, strerror(ret));
+		       __func__, port_id, strerror(-ret));
 		return;
 	}
 
 	ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
 	if (ret != 0) {
+		if (ret < 0)
+			ret = -ret;
 		printf("%s: Error: failed to get stats (port %u): %s",
 		       __func__, port_id, strerror(ret));
 		return;
@@ -333,12 +335,14 @@  nic_xstats_clear(portid_t port_id)
 	ret = rte_eth_xstats_reset(port_id);
 	if (ret != 0) {
 		printf("%s: Error: failed to reset xstats (port %u): %s",
-		       __func__, port_id, strerror(ret));
+		       __func__, port_id, strerror(-ret));
 		return;
 	}
 
 	ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
 	if (ret != 0) {
+		if (ret < 0)
+			ret = -ret;
 		printf("%s: Error: failed to get stats (port %u): %s",
 		       __func__, port_id, strerror(ret));
 		return;