cpuidle: lpm-levels: Fix possible null pointer access
Fix possible null pointer access, possible attempt to access array out of bounds and indentation. Change-Id: If32501d18f57e50aeb378ed8965bfc3e236a6b2c Signed-off-by: Srinivas Rao L <lsrao@codeaurora.org>
This commit is contained in:
parent
28caff276f
commit
180479982a
|
@ -84,7 +84,7 @@ static void set_optimum_cpu_residency(struct lpm_cpu *cpu, int cpu_id,
|
|||
|
||||
mode_avail = probe_time ||
|
||||
lpm_cpu_mode_allow(cpu_id, i, true);
|
||||
if(!mode_avail) {
|
||||
if (!mode_avail) {
|
||||
maximum_residency[i] = 0;
|
||||
minimum_residency[i] = 0;
|
||||
continue;
|
||||
|
@ -102,8 +102,8 @@ static void set_optimum_cpu_residency(struct lpm_cpu *cpu, int cpu_id,
|
|||
}
|
||||
|
||||
minimum_residency[i] = pwr->time_overhead_us;
|
||||
for(j = i-1; j >= 0; j--) {
|
||||
if(probe_time || lpm_cpu_mode_allow(cpu_id, j, true)) {
|
||||
for (j = i-1; j >= 0; j--) {
|
||||
if (probe_time || lpm_cpu_mode_allow(cpu_id, j, true)) {
|
||||
minimum_residency[i] = maximum_residency[j] + 1;
|
||||
break;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ static void set_optimum_cluster_residency(struct lpm_cluster *cluster,
|
|||
|
||||
mode_avail = probe_time ||
|
||||
lpm_cluster_mode_allow(cluster, i, true);
|
||||
if(!mode_avail) {
|
||||
if (!mode_avail) {
|
||||
pwr->max_residency = 0;
|
||||
pwr->min_residency = 0;
|
||||
continue;
|
||||
|
@ -140,9 +140,11 @@ static void set_optimum_cluster_residency(struct lpm_cluster *cluster,
|
|||
}
|
||||
|
||||
pwr->min_residency = pwr->time_overhead_us;
|
||||
for(j = i-1; j >= 0; j--) {
|
||||
if(probe_time || lpm_cluster_mode_allow(cluster, j, true)) {
|
||||
pwr->min_residency = cluster->levels[j].pwr.max_residency + 1;
|
||||
for (j = i-1; j >= 0; j--) {
|
||||
if (probe_time ||
|
||||
lpm_cluster_mode_allow(cluster, j, true)) {
|
||||
pwr->min_residency =
|
||||
cluster->levels[j].pwr.max_residency + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -183,6 +185,8 @@ ssize_t lpm_enable_store(struct kobject *kobj, struct kobj_attribute *attr,
|
|||
struct lpm_level_avail *avail;
|
||||
|
||||
avail = get_avail_ptr(kobj, attr);
|
||||
if (WARN_ON(!avail))
|
||||
return -EINVAL;
|
||||
kp.arg = get_enabled_ptr(attr, avail);
|
||||
ret = param_set_bool(buf, &kp);
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
|
||||
* Copyright (C) 2006-2007 Adam Belay <abelay@novell.com>
|
||||
* Copyright (C) 2009 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
|
@ -497,14 +499,14 @@ static inline void invalidate_predict_history(struct cpuidle_device *dev)
|
|||
static void clear_predict_history(void)
|
||||
{
|
||||
struct lpm_history *history;
|
||||
int i, j;
|
||||
int ncpus = num_present_cpus();
|
||||
int i;
|
||||
unsigned int cpu;
|
||||
|
||||
if (!lpm_prediction)
|
||||
return;
|
||||
|
||||
for (j = 0; j < ncpus; j++) {
|
||||
history = &per_cpu(hist, j);
|
||||
for_each_possible_cpu(cpu) {
|
||||
history = &per_cpu(hist, cpu);
|
||||
for (i = 0; i < MAXSAMPLES; i++) {
|
||||
history->resi[i] = 0;
|
||||
history->mode[i] = -1;
|
||||
|
@ -527,7 +529,7 @@ static int cpu_power_select(struct cpuidle_device *dev,
|
|||
(uint32_t)(ktime_to_us(tick_nohz_get_sleep_length()));
|
||||
uint32_t modified_time_us = 0;
|
||||
uint32_t next_event_us = 0;
|
||||
int i, idx_restrict = cpu->nlevels + 1;
|
||||
int i, idx_restrict;
|
||||
uint32_t lvl_latency_us = 0;
|
||||
uint64_t predicted = 0;
|
||||
uint32_t htime = 0, idx_restrict_time = 0;
|
||||
|
@ -541,6 +543,8 @@ static int cpu_power_select(struct cpuidle_device *dev,
|
|||
if (sleep_disabled)
|
||||
return 0;
|
||||
|
||||
idx_restrict = cpu->nlevels + 1;
|
||||
|
||||
next_event_us = (uint32_t)(ktime_to_us(get_next_event_time(dev->cpu)));
|
||||
|
||||
for (i = 0; i < cpu->nlevels; i++) {
|
||||
|
@ -915,9 +919,8 @@ static int cluster_select(struct lpm_cluster *cluster, bool from_idle,
|
|||
* min_residency is time overhead for current level
|
||||
*/
|
||||
if (predicted ? (pred_us >= pwr_params->min_residency)
|
||||
: (sleep_us >= pwr_params->min_residency)) {
|
||||
: (sleep_us >= pwr_params->min_residency))
|
||||
best_level = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ((best_level == (cluster->nlevels - 1)) && (pred_mode == 2))
|
||||
|
|
Loading…
Reference in New Issue