aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Yu <yu.c.chen@intel.com>2015-07-29 11:53:10 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-07-31 17:25:16 -0400
commit144c8e172b5c388ddf41fa64e154f53384ec3448 (patch)
tree13ff609371f0ba7949d392d32512a01680b0aa07
parentfba9573b33f8bddd772195c202f6b8ec0751cedd (diff)
intel_pstate: Fix possible overflow complained by Coverity
Coverity scanning performed on intel_pstate.c shows possible overflow when doing left shifting: val = pstate << 8; since pstate is of type integer, while val is of u64, left shifting pstate might lead to potential loss of upper bits. Say, if pstate equals 0x4000 0000, after pstate << 8 we will get zero assigned to val. Although pstate will not likely be that big, this patch cast the left operand to u64 before performing the left shift, to avoid complaining from Coverity. Reported-by: Coquard, Christophe <christophe.coquard@intel.com> Signed-off-by: Chen Yu <yu.c.chen@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/cpufreq/intel_pstate.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 7b2721fb861f..b9354b6f7149 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -521,7 +521,7 @@ static void byt_set_pstate(struct cpudata *cpudata, int pstate)
521 int32_t vid_fp; 521 int32_t vid_fp;
522 u32 vid; 522 u32 vid;
523 523
524 val = pstate << 8; 524 val = (u64)pstate << 8;
525 if (limits.no_turbo && !limits.turbo_disabled) 525 if (limits.no_turbo && !limits.turbo_disabled)
526 val |= (u64)1 << 32; 526 val |= (u64)1 << 32;
527 527
@@ -610,7 +610,7 @@ static void core_set_pstate(struct cpudata *cpudata, int pstate)
610{ 610{
611 u64 val; 611 u64 val;
612 612
613 val = pstate << 8; 613 val = (u64)pstate << 8;
614 if (limits.no_turbo && !limits.turbo_disabled) 614 if (limits.no_turbo && !limits.turbo_disabled)
615 val |= (u64)1 << 32; 615 val |= (u64)1 << 32;
616 616