meter: fix divide by zero for RFC4115
authorEelco Chaudron <echaudro@redhat.com>
Tue, 19 Mar 2019 12:10:44 +0000 (12:10 +0000)
committerCristian Dumitrescu <cristian.dumitrescu@intel.com>
Fri, 29 Mar 2019 19:51:25 +0000 (20:51 +0100)
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>
lib/librte_meter/rte_meter.c

index e55f9be..4567944 100644 (file)
 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;