[dpdk-dev,2/2] app/testeventdev: fix a divide by zero case

Message ID 20170731100452.12647-2-jerin.jacob@caviumnetworks.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jerin Jacob July 31, 2017, 10:04 a.m. UTC
  pkts == 0 will result in divide by zero case.
Added a check to fix it.

Coverity issue: 158652
Fixes: 9d3aeb185eb4 ("app/testeventdev: launch perf lcores")
Cc: stable@dpdk.org

Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
 app/test-eventdev/test_perf_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Van Haaren, Harry July 31, 2017, 10:09 a.m. UTC | #1
> From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]
> Sent: Monday, July 31, 2017 11:05 AM
> To: dev@dpdk.org
> Cc: thomas@monjalon.net; Richardson, Bruce <bruce.richardson@intel.com>; Van Haaren, Harry
> <harry.van.haaren@intel.com>; hemant.agrawal@nxp.com; Eads, Gage <gage.eads@intel.com>;
> nipun.gupta@nxp.com; gprathyusha@caviumnetworks.com; Jerin Jacob
> <jerin.jacob@caviumnetworks.com>; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH 2/2] app/testeventdev: fix a divide by zero case
> 
> pkts == 0 will result in divide by zero case.
> Added a check to fix it.
> 
> Coverity issue: 158652
> Fixes: 9d3aeb185eb4 ("app/testeventdev: launch perf lcores")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

Acked-by: Harry van Haaren <harry.van.haaren@intel.com>
  

Patch

diff --git a/app/test-eventdev/test_perf_common.c b/app/test-eventdev/test_perf_common.c
index a5b768c68..7b0929941 100644
--- a/app/test-eventdev/test_perf_common.c
+++ b/app/test-eventdev/test_perf_common.c
@@ -203,7 +203,7 @@  perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
 			perf_cycles = new_cycles;
 			total_mpps += mpps;
 			++samples;
-			if (opt->fwd_latency) {
+			if (opt->fwd_latency && pkts > 0) {
 				printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM,
 					mpps, total_mpps/samples,
 					(float)(latency/pkts)/freq_mhz);