From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 999B11B101; Fri, 26 Apr 2019 10:44:19 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2019 01:44:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,396,1549958400"; d="scan'208";a="146003359" Received: from silpixa00399952.ir.intel.com (HELO silpixa00399952.ger.corp.intel.com) ([10.237.223.64]) by fmsmga007.fm.intel.com with ESMTP; 26 Apr 2019 01:44:17 -0700 From: David Hunt To: dev@dpdk.org Cc: david.hunt@intel.com, stable@dpdk.org Date: Fri, 26 Apr 2019 09:44:15 +0100 Message-Id: <20190426084415.3979-1-david.hunt@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v1] examples/vm_power_manager: fix overflowed return value 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: Fri, 26 Apr 2019 08:44:20 -0000 Coverity complains about the return of a value that may possibly overflow because of a multiply. Limit the value so it cannot overflow. Coverity issue: 337677 Fixes: 4b1a631b8a ("examples/vm_power: add oob monitoring functions") CC: stable@dpdk.org Signed-off-by: David Hunt --- examples/vm_power_manager/oob_monitor_x86.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/vm_power_manager/oob_monitor_x86.c b/examples/vm_power_manager/oob_monitor_x86.c index ebd96b205..2074eec1e 100644 --- a/examples/vm_power_manager/oob_monitor_x86.c +++ b/examples/vm_power_manager/oob_monitor_x86.c @@ -99,7 +99,10 @@ apply_policy(int core) return -1.0; } - ratio = (float)miss_diff * (float)100 / (float)hits_diff; + ratio = (float)miss_diff / (float)hits_diff; + if (ratio > 1.0) + ratio = 1.0; + ratio *= 100.0f; if (ratio < ci->branch_ratio_threshold) power_manager_scale_core_min(core); -- 2.17.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 7999CA05D3 for ; Fri, 26 Apr 2019 10:44:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 28AB31B596; Fri, 26 Apr 2019 10:44:21 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 999B11B101; Fri, 26 Apr 2019 10:44:19 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2019 01:44:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,396,1549958400"; d="scan'208";a="146003359" Received: from silpixa00399952.ir.intel.com (HELO silpixa00399952.ger.corp.intel.com) ([10.237.223.64]) by fmsmga007.fm.intel.com with ESMTP; 26 Apr 2019 01:44:17 -0700 From: David Hunt To: dev@dpdk.org Cc: david.hunt@intel.com, stable@dpdk.org Date: Fri, 26 Apr 2019 09:44:15 +0100 Message-Id: <20190426084415.3979-1-david.hunt@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v1] examples/vm_power_manager: fix overflowed return value 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190426084415.Tn_McNQJJYCN3_igHCbcmEmdEH0S5VR4HRUidshAxOE@z> Coverity complains about the return of a value that may possibly overflow because of a multiply. Limit the value so it cannot overflow. Coverity issue: 337677 Fixes: 4b1a631b8a ("examples/vm_power: add oob monitoring functions") CC: stable@dpdk.org Signed-off-by: David Hunt --- examples/vm_power_manager/oob_monitor_x86.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/vm_power_manager/oob_monitor_x86.c b/examples/vm_power_manager/oob_monitor_x86.c index ebd96b205..2074eec1e 100644 --- a/examples/vm_power_manager/oob_monitor_x86.c +++ b/examples/vm_power_manager/oob_monitor_x86.c @@ -99,7 +99,10 @@ apply_policy(int core) return -1.0; } - ratio = (float)miss_diff * (float)100 / (float)hits_diff; + ratio = (float)miss_diff / (float)hits_diff; + if (ratio > 1.0) + ratio = 1.0; + ratio *= 100.0f; if (ratio < ci->branch_ratio_threshold) power_manager_scale_core_min(core); -- 2.17.1