DPDK patches and discussions
 help / color / mirror / Atom feed
From: Eelco Chaudron <echaudro@redhat.com>
To: cristian.dumitrescu@intel.com
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2] lib/librte_meter: fix divide by zero for RFC4115 meter
Date: Fri,  1 Feb 2019 16:07:16 +0000	[thread overview]
Message-ID: <154903721465.46418.12675922836824541692.stgit@dbuild> (raw)

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

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;
 

             reply	other threads:[~2019-02-01 16:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 16:07 Eelco Chaudron [this message]
2019-02-05  8:40 ` Jens Freimann
2019-02-28 18:50 ` Dumitrescu, Cristian
2019-03-19 11:00   ` Eelco Chaudron
2019-03-19 11:00     ` Eelco Chaudron

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=154903721465.46418.12675922836824541692.stgit@dbuild \
    --to=echaudro@redhat.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /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).