summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hunt <david.hunt@intel.com>2019-07-10 16:26:20 +0100
committerThomas Monjalon <thomas@monjalon.net>2019-07-11 00:00:46 +0200
commit018faf21d670e06d51beb52e1c3c12192a762339 (patch)
tree083ac57938953ce0de26d5833b921e6e7f2b8a7a
parent221e7026d521c97c58fcee867f003e414dba2eea (diff)
downloaddpdk-018faf21d670e06d51beb52e1c3c12192a762339.zip
dpdk-018faf21d670e06d51beb52e1c3c12192a762339.tar.gz
dpdk-018faf21d670e06d51beb52e1c3c12192a762339.tar.xz
examples/l3fwd-power: fix metrics divisions
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>
-rw-r--r--examples/l3fwd-power/main.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 99c1208..7a95605 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)