[v2] lib/librte_meter: fix divide by zero for RFC4115 meter

Message ID 154903721465.46418.12675922836824541692.stgit@dbuild
State New
Delegated to: Cristian Dumitrescu
Headers show
Series
  • [v2] lib/librte_meter: fix divide by zero for RFC4115 meter
Related show

Checks

Context Check Description
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Eelco Chaudron Feb. 1, 2019, 4:07 p.m.
RFC 4115 allows a meter with either cir and/or eir configured.
When only one is configured a divide by zero would occur.

Fixes: 655796d2b5fb ("meter: support RFC4115 trTCM")
Cc: echaudro@redhat.com

Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
---

 v2 - Removed configuration change that got included by accident

 lib/librte_meter/rte_meter.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Jens Freimann Feb. 5, 2019, 8:40 a.m. | #1
On Fri, Feb 01, 2019 at 04:07:16PM +0000, Eelco Chaudron wrote:
>RFC 4115 allows a meter with either cir and/or eir configured.
>When only one is configured a divide by zero would occur.
>
>Fixes: 655796d2b5fb ("meter: support RFC4115 trTCM")
>Cc: echaudro@redhat.com
>
>Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
>---
>
> v2 - Removed configuration change that got included by accident
>
> lib/librte_meter/rte_meter.h |    8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>

Reviewed-by: Jens Freimann <jfreimann@redhat.com>

Patch

diff --git a/lib/librte_meter/rte_meter.h b/lib/librte_meter/rte_meter.h
index 005e4eeee..56d85ecf0 100644
--- a/lib/librte_meter/rte_meter.h
+++ b/lib/librte_meter/rte_meter.h
@@ -597,8 +597,8 @@  rte_meter_trtcm_rfc4115_color_blind_check(
 	/* Bucket update */
 	time_diff_tc = time - m->time_tc;
 	time_diff_te = time - m->time_te;
-	n_periods_tc = time_diff_tc / p->cir_period;
-	n_periods_te = time_diff_te / p->eir_period;
+	n_periods_tc = p->cir_period != 0 ? time_diff_tc / p->cir_period : 0;
+	n_periods_te = p->eir_period != 0 ? time_diff_te / p->eir_period : 0;
 	m->time_tc += n_periods_tc * p->cir_period;
 	m->time_te += n_periods_te * p->eir_period;
 
@@ -641,8 +641,8 @@  rte_meter_trtcm_rfc4115_color_aware_check(
 	/* Bucket update */
 	time_diff_tc = time - m->time_tc;
 	time_diff_te = time - m->time_te;
-	n_periods_tc = time_diff_tc / p->cir_period;
-	n_periods_te = time_diff_te / p->eir_period;
+	n_periods_tc = p->cir_period != 0 ? time_diff_tc / p->cir_period : 0;
+	n_periods_te = p->eir_period != 0 ? time_diff_te / p->eir_period : 0;
 	m->time_tc += n_periods_tc * p->cir_period;
 	m->time_te += n_periods_te * p->eir_period;