From: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
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 <shilpa.bhat@linux.vnet.ibm.com>
Subject: [PATCH] cpufreq: powernv: Check negative value returned by cpufreq_table_find_index_dl()
Date: Mon, 12 Feb 2018 15:51:16 +0530 [thread overview]
Message-ID: <1518430876-24464-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> (raw)
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 <shilpa.bhat@linux.vnet.ibm.com>
---
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);
--
1.8.3.1
next reply other threads:[~2018-02-12 10:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-12 10:21 Shilpasri G Bhat [this message]
2018-02-12 10:29 ` [PATCH] cpufreq: powernv: Check negative value returned by cpufreq_table_find_index_dl() Viresh Kumar
2018-02-12 10:33 ` Shilpasri G Bhat
2018-02-12 10:40 ` Viresh Kumar
2018-02-26 9:48 ` Rafael J. Wysocki
2018-02-21 5:39 ` Michael Ellerman
2018-02-21 5:54 ` Viresh Kumar
2018-02-21 9:27 ` Rafael J. Wysocki
2018-02-21 10:02 ` Viresh Kumar
2018-02-21 10:17 ` Rafael J. Wysocki
2018-02-21 10:19 ` Viresh Kumar
2018-02-21 13:13 ` Michael Ellerman
2018-02-21 13:25 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1518430876-24464-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com \
--to=shilpa.bhat@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=rjw@rjwysocki.net \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).