soc: qcom: Avoid accessing invalid CPU ids

While getting input for min and max freq from userspace,
checking against just the number of present CPUs can
cause an access to an invalid CPU id if the userspace
input is not properly constructed for a particular
target.
This change prevents that from happening by
checking against num_present_cpus() - 1 so that
invalid CPU ids are not considered while accepting
input from userspace.

Change-Id: I9e52a175ff8ea9448a0676695a63ffddfa12419e
Signed-off-by: Pracheer <pracheer@codeaurora.org>
This commit is contained in:
Pracheer 2014-12-11 13:52:36 +05:30 committed by David Keitel
parent d4fe676390
commit a47233f55b

View file

@ -248,7 +248,7 @@ static int set_cpu_min_freq(const char *buf, const struct kernel_param *kp)
for (i = 0; i < ntokens; i += 2) {
if (sscanf(cp, "%u:%u", &cpu, &val) != 2)
return -EINVAL;
if (cpu > num_present_cpus())
if (cpu > (num_present_cpus() - 1))
return -EINVAL;
i_cpu_stats = &per_cpu(cpu_stats, cpu);
@ -331,7 +331,7 @@ static int set_cpu_max_freq(const char *buf, const struct kernel_param *kp)
for (i = 0; i < ntokens; i += 2) {
if (sscanf(cp, "%u:%u", &cpu, &val) != 2)
return -EINVAL;
if (cpu > num_present_cpus())
if (cpu > (num_present_cpus() - 1))
return -EINVAL;
i_cpu_stats = &per_cpu(cpu_stats, cpu);