DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v3] app/testpmd: fix passing negative parameter to strerror
@ 2020-06-06  3:46 Wei Hu (Xavier)
  2020-06-08 14:47 ` Ferruh Yigit
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Hu (Xavier) @ 2020-06-06  3:46 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev, xavier.huwei

Currently, there are coverity defect warnings those were found from the
public coverity.
https://scan.coverity.com/projects/dpdk-data-plane-development-kit

Coverity issue:
  In nic_stats_clear function:
    CID 358450 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
    5. negative_returns: ret is passed to a parameter that cannot be
       negative.

    CID 358449 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
    6. negative_returns: ret is passed to a parameter that cannot be
       negative.

  In nic_xstats_clear function:
    CID 358437 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
    6. negative_returns: ret is passed to a parameter that cannot be
       negative.

    CID 349913 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
    5. negative_returns: ret is passed to a parameter that cannot be
       negative.

This patch fixes them by passing '-ret' to the function strerror() when ret
is 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>
---
v2 -> v3:
	1. replace the coverity warning infromation with the ones found
	   from the public coverity in the commit log.

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

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;
-- 
2.7.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH v3] app/testpmd: fix passing negative parameter to strerror
  2020-06-06  3:46 [dpdk-dev] [PATCH v3] app/testpmd: fix passing negative parameter to strerror Wei Hu (Xavier)
@ 2020-06-08 14:47 ` Ferruh Yigit
  0 siblings, 0 replies; 2+ messages in thread
From: Ferruh Yigit @ 2020-06-08 14:47 UTC (permalink / raw)
  To: Wei Hu (Xavier); +Cc: dev

On 6/6/2020 4:46 AM, Wei Hu (Xavier) wrote:
> Currently, there are coverity defect warnings those were found from the
> public coverity.
> https://scan.coverity.com/projects/dpdk-data-plane-development-kit
> 
> Coverity issue:
>   In nic_stats_clear function:
>     CID 358450 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
>     5. negative_returns: ret is passed to a parameter that cannot be
>        negative.
> 
>     CID 358449 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
>     6. negative_returns: ret is passed to a parameter that cannot be
>        negative.
> 
>   In nic_xstats_clear function:
>     CID 358437 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
>     6. negative_returns: ret is passed to a parameter that cannot be
>        negative.
> 
>     CID 349913 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
>     5. negative_returns: ret is passed to a parameter that cannot be
>        negative.


Shortened above as following:
    Coverity issue: 349913, 358437, 358449, 358450

> 
> This patch fixes them by passing '-ret' to the function strerror() when ret
> is 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>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/master, thanks.

> ---
> v2 -> v3:
> 	1. replace the coverity warning infromation with the ones found
> 	   from the public coverity in the commit log.

Thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-08 14:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-06  3:46 [dpdk-dev] [PATCH v3] app/testpmd: fix passing negative parameter to strerror Wei Hu (Xavier)
2020-06-08 14:47 ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).