From: David Hunt <david.hunt@intel.com>
To: dev@dpdk.org
Cc: david.hunt@intel.com, reshma.pattan@intel.com
Subject: [dpdk-dev] [PATCH v1] examples/l3fwd-power: fix telemetry coverity issue
Date: Wed, 10 Jul 2019 16:26:20 +0100 [thread overview]
Message-ID: <20190710152620.9365-1-david.hunt@intel.com> (raw)
6 issues caught by Coverity 343465
* Possible divide by zero on 3 lines
* Convert to float then back to int, losing precision on 3 lines
This patch modifies the code so that it only assigns calculated
values if the divisor is > 0, otherwise sets metrics to zero.
Also removes the un-needed round() function.
Coverity issue: 343465
Fixes: 609e79841fcf ("examples/l3fwd-power: add telemetry mode")
Signed-off-by: David Hunt <david.hunt@intel.com>
---
examples/l3fwd-power/main.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 99c1208ce..7a95605c4 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -2100,9 +2100,16 @@ update_telemetry(__attribute__((unused)) struct rte_timer *tim,
rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
}
- values[0] = round(app_eps/count);
- values[1] = round(app_fps/count);
- values[2] = round(app_br/count);
+ if (count > 0) {
+ values[0] = app_eps/count;
+ values[1] = app_fps/count;
+ values[2] = app_br/count;
+ } else {
+ values[0] = 0;
+ values[1] = 0;
+ values[2] = 0;
+ }
+
ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, telstats_index,
values, RTE_DIM(values));
if (ret < 0)
--
2.17.1
next reply other threads:[~2019-07-10 15:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 15:26 David Hunt [this message]
2019-07-10 22:00 ` Thomas Monjalon
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=20190710152620.9365-1-david.hunt@intel.com \
--to=david.hunt@intel.com \
--cc=dev@dpdk.org \
--cc=reshma.pattan@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;
as well as URLs for NNTP newsgroup(s).