From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933861AbeBLK3F (ORCPT ); Mon, 12 Feb 2018 05:29:05 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:43156 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932868AbeBLK3D (ORCPT ); Mon, 12 Feb 2018 05:29:03 -0500 X-Google-Smtp-Source: AH8x225YyjH2FjZVQAd3OrIgp7g3vx2DE0cS+prkD3Rfmc6LJOq/ZBXpk7WtkMa4WMhtJXPS0h7zVg== Date: Mon, 12 Feb 2018 15:59:00 +0530 From: Viresh Kumar To: Shilpasri G Bhat Cc: rjw@rjwysocki.net, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, mpe@ellerman.id.au Subject: Re: [PATCH] cpufreq: powernv: Check negative value returned by cpufreq_table_find_index_dl() Message-ID: <20180212102900.GU28462@vireshk-i7> References: <1518430876-24464-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1518430876-24464-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12-02-18, 15:51, Shilpasri G Bhat wrote: > This patch fixes the below Coverity warning: > > *** CID 182816: Memory - illegal accesses (NEGATIVE_RETURNS) > /drivers/cpufreq/powernv-cpufreq.c: 1008 in powernv_fast_switch() > 1002 unsigned int target_freq) > 1003 { > 1004 int index; > 1005 struct powernv_smp_call_data freq_data; > 1006 > 1007 index = cpufreq_table_find_index_dl(policy, target_freq); > >>> CID 182816: Memory - illegal accesses (NEGATIVE_RETURNS) > >>> Using variable "index" as an index to array "powernv_freqs". > 1008 freq_data.pstate_id = powernv_freqs[index].driver_data; > 1009 freq_data.gpstate_id = powernv_freqs[index].driver_data; > 1010 set_pstate(&freq_data); > 1011 > 1012 return powernv_freqs[index].frequency; > 1013 } > > Signed-off-by: Shilpasri G Bhat > --- > drivers/cpufreq/powernv-cpufreq.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c > index 29cdec1..69edfe9 100644 > --- a/drivers/cpufreq/powernv-cpufreq.c > +++ b/drivers/cpufreq/powernv-cpufreq.c > @@ -1005,6 +1005,9 @@ static unsigned int powernv_fast_switch(struct cpufreq_policy *policy, > struct powernv_smp_call_data freq_data; > > index = cpufreq_table_find_index_dl(policy, target_freq); > + if (unlikely(index < 0)) > + index = get_nominal_index(); > + AFAICT, you will get -1 here only if the freq table had no valid frequencies (or the freq table is empty). Why would that happen ? > freq_data.pstate_id = powernv_freqs[index].driver_data; > freq_data.gpstate_id = powernv_freqs[index].driver_data; > set_pstate(&freq_data); > -- > 1.8.3.1 -- viresh