From 7cb6fcfa75ff503fc335eff51eeb7c9504356b2b Mon Sep 17 00:00:00 2001 From: Archana Sathyakumar Date: Tue, 13 Sep 2016 14:36:04 -0600 Subject: power: qcom: ea: Fix uninitialized temperature and cpu variable In trigger_cpu_pwr_stats_calc(), if the local variable 'prev_temp' is already updated with the latest temperature then temp might be used uninitialized. When scheduler's power data snapshot updates in the sampling thread, update the temperature as well if the temperature has been the same for some duration such that temp is used only when the sensor is read. In update_userspace_power, incorrect cpumask could cause the function to use uninitialized cpu variable. Initialize it to -1 at the beginning of the function and treat unmodified value as error condition. Change-Id: Ieccdc3f54f9c9f2cecc6b8578400c6fe44333177 Signed-off-by: Archana Sathyakumar --- drivers/power/qcom/msm-core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/power/qcom/msm-core.c b/drivers/power/qcom/msm-core.c index e990425bd63a..727a768e63eb 100644 --- a/drivers/power/qcom/msm-core.c +++ b/drivers/power/qcom/msm-core.c @@ -240,10 +240,10 @@ void trigger_cpu_pwr_stats_calc(void) if (cpu_node->sensor_id < 0) continue; - if (cpu_node->temp == prev_temp[cpu]) + if (cpu_node->temp == prev_temp[cpu]) { sensor_get_temp(cpu_node->sensor_id, &temp); - - cpu_node->temp = temp / scaling_factor; + cpu_node->temp = temp / scaling_factor; + } prev_temp[cpu] = cpu_node->temp; @@ -373,7 +373,7 @@ static int update_userspace_power(struct sched_params __user *argp) { int i; int ret; - int cpu; + int cpu = -1; struct cpu_activity_info *node; struct cpu_static_info *sp, *clear_sp; int cpumask, cluster, mpidr; @@ -396,7 +396,7 @@ static int update_userspace_power(struct sched_params __user *argp) } } - if (cpu >= num_possible_cpus()) + if ((cpu < 0) || (cpu >= num_possible_cpus())) return -EINVAL; node = &activity[cpu]; -- cgit v1.2.3