From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 7A5E6A3 for ; Tue, 19 Mar 2019 13:10:50 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B27D858E3E; Tue, 19 Mar 2019 12:10:49 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-79.ams2.redhat.com [10.36.116.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31E101B5BB; Tue, 19 Mar 2019 12:10:49 +0000 (UTC) From: Eelco Chaudron To: cristian.dumitrescu@intel.com Cc: dev@dpdk.org Date: Tue, 19 Mar 2019 12:10:44 +0000 Message-Id: <155299743267.6865.5001245009415554669.stgit@dbuild> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 19 Mar 2019 12:10:49 +0000 (UTC) Subject: [dpdk-dev] [PATCH v3] lib/librte_meter: fix divide by zero for RFC4115 meter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Mar 2019 12:10:50 -0000 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 --- 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(-) diff --git a/lib/librte_meter/rte_meter.c b/lib/librte_meter/rte_meter.c index e55f9be65..45679444e 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; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 0E921A00E6 for ; Tue, 19 Mar 2019 13:10:53 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5C99E11A4; Tue, 19 Mar 2019 13:10:52 +0100 (CET) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 7A5E6A3 for ; Tue, 19 Mar 2019 13:10:50 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B27D858E3E; Tue, 19 Mar 2019 12:10:49 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-79.ams2.redhat.com [10.36.116.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31E101B5BB; Tue, 19 Mar 2019 12:10:49 +0000 (UTC) From: Eelco Chaudron To: cristian.dumitrescu@intel.com Cc: dev@dpdk.org Date: Tue, 19 Mar 2019 12:10:44 +0000 Message-Id: <155299743267.6865.5001245009415554669.stgit@dbuild> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 19 Mar 2019 12:10:49 +0000 (UTC) Subject: [dpdk-dev] [PATCH v3] lib/librte_meter: fix divide by zero for RFC4115 meter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190319121044.oFUBzyHH2eWCbER0WBNurXQwZ1o-emiCujkAnswkjRc@z> 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 --- 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(-) diff --git a/lib/librte_meter/rte_meter.c b/lib/librte_meter/rte_meter.c index e55f9be65..45679444e 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;