summaryrefslogtreecommitdiff
path: root/lib/librte_meter
diff options
context:
space:
mode:
authorEelco Chaudron <echaudro@redhat.com>2019-03-19 12:10:44 +0000
committerCristian Dumitrescu <cristian.dumitrescu@intel.com>2019-03-29 20:51:25 +0100
commitebe3a769911071450acb808153ec2a2496726906 (patch)
tree2f9f5b1beaab1c77e5a12c205d931403cca4ca75 /lib/librte_meter
parent82010ef55e7cb4948b4bf4ff229716a3a142e95c (diff)
downloaddpdk-ebe3a769911071450acb808153ec2a2496726906.zip
dpdk-ebe3a769911071450acb808153ec2a2496726906.tar.gz
dpdk-ebe3a769911071450acb808153ec2a2496726906.tar.xz
meter: fix divide by zero for RFC4115
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") Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
Diffstat (limited to 'lib/librte_meter')
-rw-r--r--lib/librte_meter/rte_meter.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/librte_meter/rte_meter.c b/lib/librte_meter/rte_meter.c
index e55f9be..4567944 100644
--- a/lib/librte_meter/rte_meter.c
+++ b/lib/librte_meter/rte_meter.c
@@ -19,7 +19,15 @@
static void
rte_meter_get_tb_params(uint64_t hz, uint64_t rate, uint64_t *tb_period, uint64_t *tb_bytes_per_period)
{
- double period = ((double) hz) / ((double) rate);
+ double period;
+
+ if (rate == 0) {
+ *tb_bytes_per_period = 0;
+ *tb_period = RTE_METER_TB_PERIOD_MIN;
+ return;
+ }
+
+ period = ((double) hz) / ((double) rate);
if (period >= RTE_METER_TB_PERIOD_MIN) {
*tb_bytes_per_period = 1;