From patchwork Mon Feb 12 10:21:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 10212173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A74A160467 for ; Mon, 12 Feb 2018 10:21:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9567428B8F for ; Mon, 12 Feb 2018 10:21:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89DB828B94; Mon, 12 Feb 2018 10:21:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4150A28B8F for ; Mon, 12 Feb 2018 10:21:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933893AbeBLKVa (ORCPT ); Mon, 12 Feb 2018 05:21:30 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60694 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933569AbeBLKV2 (ORCPT ); Mon, 12 Feb 2018 05:21:28 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1CAK0Qp132438 for ; Mon, 12 Feb 2018 05:21:27 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2g30dy15d3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 12 Feb 2018 05:21:27 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 12 Feb 2018 10:21:25 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 12 Feb 2018 10:21:23 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w1CALM1K37748866; Mon, 12 Feb 2018 10:21:22 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 95E3CAE045; Mon, 12 Feb 2018 10:12:28 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CEDEAAE055; Mon, 12 Feb 2018 10:12:26 +0000 (GMT) Received: from oc4502181600.ibm.com (unknown [9.84.225.146]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 12 Feb 2018 10:12:26 +0000 (GMT) From: Shilpasri G Bhat To: rjw@rjwysocki.net Cc: linux-pm@vger.kernel.org, viresh.kumar@linaro.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, mpe@ellerman.id.au, Shilpasri G Bhat Subject: [PATCH] cpufreq: powernv: Check negative value returned by cpufreq_table_find_index_dl() Date: Mon, 12 Feb 2018 15:51:16 +0530 X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 x-cbid: 18021210-0040-0000-0000-0000040ECC8C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18021210-0041-0000-0000-000026128AB1 Message-Id: <1518430876-24464-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-02-12_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802120134 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(); + freq_data.pstate_id = powernv_freqs[index].driver_data; freq_data.gpstate_id = powernv_freqs[index].driver_data; set_pstate(&freq_data);