Received: by 10.223.185.116 with SMTP id b49csp3550575wrg; Mon, 26 Feb 2018 01:49:27 -0800 (PST) X-Google-Smtp-Source: AG47ELtMsvcI/wko6jzPhi9N0Pfb6AyX+YYbZfabA565NO635L3lLE5hnW86nlO3tyQZILxikRkT X-Received: by 2002:a17:902:3124:: with SMTP id w33-v6mr5612913plb.119.1519638567895; Mon, 26 Feb 2018 01:49:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519638567; cv=none; d=google.com; s=arc-20160816; b=enWqFDjYcAXPUQX4DsTn4LEkjnh36TfYjpY8cBsQ2h4ZvzC9sFIE9lBCcpBVWQrrnH +9iftZl56mo7IgysVDT/wRJREp/fRUzKYcGssnt47vweIYAGibq7134Qq0GjS/wfutjz R4h8jL3/PUCBZg2K2AN6bL61qU/Ca6RghCEoPq7M9sMBYR5E5T5UAMDt5UHjwYoQPFFh wAEq787o5WbAJvV12QgMjeLblsoKZFEkWTYTddLcWS5seh21KxICqeP6BpkR3Ah+zsBh lWNoKmW/9lyJNqQ1qtlAqo2vFiU4YkXPnJRyDwVbBJ/JgsOVlNZ5GfRQipl/xKLVyvL4 mlXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=76QMlMDtBtOPDpU5n7dKxNz2uHCnYcYqCFt4AVCklCM=; b=hlpXj4JZh9D6w+84w6Iwm5Gyu9gIqSyJyxzgpkTRy49tP9UaqC1rnLCOfUvJlrkxky gBz47Z1Rw/V6e2zTMKMnfay7FzVdQizO3uZB0q1c8eVBuWVj0eg/icWgQA8OH34AK5hK 0ACDowYr01ETI7zLReYSpiPE1wEGuGeYAXa1RnnUmukOysF6ZEPyBbzyoTlpOc7SuWdt i198Jnb40O61iW8usvl86v1k+5hpEdQfs9rczTO908vVMk9mCvkj/lMBCFhXIPAVhHCk toBnN3uRbbiIvmRll/N5XsH3IwDKQxDAAe8lmZe9xlXulRYM21hIJjcvY81lAmXYGfiO dEZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UJMz/u7R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 124si6520340pfu.109.2018.02.26.01.49.13; Mon, 26 Feb 2018 01:49:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UJMz/u7R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752517AbeBZJsY (ORCPT + 99 others); Mon, 26 Feb 2018 04:48:24 -0500 Received: from mail-oi0-f65.google.com ([209.85.218.65]:39159 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752451AbeBZJsU (ORCPT ); Mon, 26 Feb 2018 04:48:20 -0500 Received: by mail-oi0-f65.google.com with SMTP id t185so10163262oif.6; Mon, 26 Feb 2018 01:48:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=76QMlMDtBtOPDpU5n7dKxNz2uHCnYcYqCFt4AVCklCM=; b=UJMz/u7RG4KTNndnBkL8hDiXMhbNSzqliuHrMKAx/JyLTREP5VZ5z+O2nniXoPNmAg iii51mtTLc9e97ob/2dj+g+7VreUNTWxUK3yL0gioep4+arzpHjNzjSXiEqc6UbzpAEP bgxDhCnPOOMEl4CqlmUFk/uW9NTGJVP6XVpnY5SHrVKocsKCmgu3dnqUOFKKzfBFU5CA KNHoXTSMPIdiC1b9AqpMA5S7OUQrn9blmGdQjtlaP4ipf4OTFEHfJphaFKFXi6QUDBCk 2lXsyn9pChErNqVcAOM7sz4xT0gZKSuZp0YHp5UPKJAD2zrutI4nUXWs5A/IeMaGb9mx oH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=76QMlMDtBtOPDpU5n7dKxNz2uHCnYcYqCFt4AVCklCM=; b=BvBco175vJOUwdjs3MN+nMDXchXTs+AX1B1a7RXlscJ9G0Vkbrw5Yij5n1dzU7pf3P BoAgs0i9k0zUxIqh0jE0RWAkioWJ+1Er4OsK/9xr4QlwQvZ7xEy5xVZsKV0/pDoUVrkx cgxDW1GPMvguOrlP9R4wm5qFHOHoFiYR96aYWLVBADXsbxaWET6jxV22uuEBWt3OnPUE CGY0sBEwZ7Xr3gxnPvD19pA3/8CuQe+ugDYHi1L56rXOE3GaGoTH5stmdYTV7xbT/06x 7XNU8LJDOcd4YrHr1MjsiyfdZ77XBPsoJC4/VWG0ZsChVbfWzmR9Wz4HjeJ2ODuksqCf yK5A== X-Gm-Message-State: APf1xPATJ1/P+4vQw0YN4WMFQEzdFSLspB+CVU5QwFfggcDDMIaWw2UG Esr0UcuuPtajb+IXL4MfZ/woMlMKQ5WPWIOpfNI= X-Received: by 10.202.230.209 with SMTP id d200mr6428516oih.174.1519638499784; Mon, 26 Feb 2018 01:48:19 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.44.146 with HTTP; Mon, 26 Feb 2018 01:48:19 -0800 (PST) In-Reply-To: <14e2fe70-7628-4377-664d-3c4b0071e08d@linux.vnet.ibm.com> References: <1518430876-24464-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> <20180212102900.GU28462@vireshk-i7> <14e2fe70-7628-4377-664d-3c4b0071e08d@linux.vnet.ibm.com> From: "Rafael J. Wysocki" Date: Mon, 26 Feb 2018 10:48:19 +0100 X-Google-Sender-Auth: L-fNLenWZ4pCGGwFxiEb_ET-FiY Message-ID: Subject: Re: [PATCH] cpufreq: powernv: Check negative value returned by cpufreq_table_find_index_dl() To: Shilpasri G Bhat Cc: Viresh Kumar , "Rafael J. Wysocki" , Linux PM , Linux Kernel Mailing List , linuxppc-dev , Michael Ellerman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 12, 2018 at 11:33 AM, Shilpasri G Bhat wrote: > Hi, > > On 02/12/2018 03:59 PM, Viresh Kumar wrote: >> 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 ? > > I agree too. There is no way we can get -1 with initialized cpu frequency table. > We don't initialize powernv-cpufreq if we don't have valid CPU frequency > entries. Is there any other way to suppress the Coverity tool warning apart from > ignoring it? In principle you could use BUG_ON(something_impossible) to annotate that kind of thing to the static analysis tools, but that would generate extra code.