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 6010AA05D3 for ; Fri, 26 Apr 2019 12:29:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 38C361B60F; Fri, 26 Apr 2019 12:29:07 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 334091B5DF; Fri, 26 Apr 2019 12:29:05 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2019 03:29:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,397,1549958400"; d="scan'208";a="153950167" Received: from aburakov-mobl1.ger.corp.intel.com (HELO [10.251.92.20]) ([10.251.92.20]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2019 03:29:01 -0700 To: David Hunt , dev@dpdk.org Cc: stable@dpdk.org References: <20190426084415.3979-1-david.hunt@intel.com> From: "Burakov, Anatoly" Message-ID: Date: Fri, 26 Apr 2019 11:29:01 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190426084415.3979-1-david.hunt@intel.com> Content-Type: text/plain; charset="UTF-8"; format="flowed" Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [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" Message-ID: <20190426102901.LGRzmo4SkX26ZnmIB8OJxEn4q9Tpv6KPc9ggvAmRqoI@z> On 26-Apr-19 9:44 AM, David Hunt wrote: > 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; It should probably be the other way around - multiply first, then clamp. Also, please use RTE_MIN. > > if (ratio < ci->branch_ratio_threshold) > power_manager_scale_core_min(core); > -- Thanks, Anatoly