From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5ED25A00E6 for ; Wed, 10 Jul 2019 17:26:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3B1FB2C60; Wed, 10 Jul 2019 17:26:34 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 15F2A3DC for ; Wed, 10 Jul 2019 17:26:32 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2019 08:26:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,475,1557212400"; d="scan'208";a="189203789" Received: from silpixa00399952.ir.intel.com (HELO silpixa00399952.ger.corp.intel.com) ([10.237.222.88]) by fmsmga004.fm.intel.com with ESMTP; 10 Jul 2019 08:26:30 -0700 From: David Hunt To: dev@dpdk.org Cc: david.hunt@intel.com, reshma.pattan@intel.com Date: Wed, 10 Jul 2019 16:26:20 +0100 Message-Id: <20190710152620.9365-1-david.hunt@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v1] examples/l3fwd-power: fix telemetry coverity issue 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" 6 issues caught by Coverity 343465 * Possible divide by zero on 3 lines * Convert to float then back to int, losing precision on 3 lines This patch modifies the code so that it only assigns calculated values if the divisor is > 0, otherwise sets metrics to zero. Also removes the un-needed round() function. Coverity issue: 343465 Fixes: 609e79841fcf ("examples/l3fwd-power: add telemetry mode") Signed-off-by: David Hunt --- examples/l3fwd-power/main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index 99c1208ce..7a95605c4 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -2100,9 +2100,16 @@ update_telemetry(__attribute__((unused)) struct rte_timer *tim, rte_spinlock_unlock(&stats[lcore_id].telemetry_lock); } - values[0] = round(app_eps/count); - values[1] = round(app_fps/count); - values[2] = round(app_br/count); + if (count > 0) { + values[0] = app_eps/count; + values[1] = app_fps/count; + values[2] = app_br/count; + } else { + values[0] = 0; + values[1] = 0; + values[2] = 0; + } + ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, telstats_index, values, RTE_DIM(values)); if (ret < 0) -- 2.17.1