Skip to contentSkip to conversation

lib/librte_meter: fix divide by zero for RFC4115 meter

PATCH Applied Eelco Chaudron 2 participants 2 messages Mar 19, 2019 – Mar 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 lib/librte_meter: fix divide by zero for RFC4115 meter

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

---
v3 - Rather than using a 0 check, set up profile data such that no
check at runtime is needed.
v2 - Removed configuration change that got included by accident

 lib/librte_meter/rte_meter.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
lib/librte_meter/rte_meter.c +9 -1
index e55f9be65..45679444e 100644
@@ -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;
Acked-by on v3 1/1 Applied
#1 lore raw
Quoted 15 lines

-----Original Message-----
From: Eelco Chaudron [mailto:[email protected]]
Sent: Tuesday, March 19, 2019 12:11 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: [email protected]
Subject: [PATCH v3] lib/librte_meter: fix divide by zero for RFC4115 meter

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")
Quoted 7 lines

---
v3 - Rather than using a 0 check, set up profile data such that no
check at runtime is needed.
v2 - Removed configuration change that got included by accident

Applied to the next-qos tree, thanks!