Commit 25aca347 authored by Cesar Eduardo Barros's avatar Cesar Eduardo Barros Committed by Dave Jones

[CPUFREQ] fix show_trans_table

Fix show_trans_table when it overflows PAGE_SIZE.

* Not all snprintf calls were protected against being passed a negative
length.
* When show_trans_table overflows, len might be > PAGE_SIZE. In that case,
returns PAGE_SIZE.
Signed-off-by: default avatarCesar Eduardo Barros <cesarb@cesarb.net>
Signed-off-by: default avatarDave Jones <davej@codemonkey.org.uk>
parent 74212ca4
...@@ -114,7 +114,7 @@ show_trans_table(struct cpufreq_policy *policy, char *buf) ...@@ -114,7 +114,7 @@ show_trans_table(struct cpufreq_policy *policy, char *buf)
stat->freq_table[i]); stat->freq_table[i]);
} }
if (len >= PAGE_SIZE) if (len >= PAGE_SIZE)
return len; return PAGE_SIZE;
len += snprintf(buf + len, PAGE_SIZE - len, "\n"); len += snprintf(buf + len, PAGE_SIZE - len, "\n");
...@@ -131,8 +131,12 @@ show_trans_table(struct cpufreq_policy *policy, char *buf) ...@@ -131,8 +131,12 @@ show_trans_table(struct cpufreq_policy *policy, char *buf)
len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", len += snprintf(buf + len, PAGE_SIZE - len, "%9u ",
stat->trans_table[i*stat->max_state+j]); stat->trans_table[i*stat->max_state+j]);
} }
if (len >= PAGE_SIZE)
break;
len += snprintf(buf + len, PAGE_SIZE - len, "\n"); len += snprintf(buf + len, PAGE_SIZE - len, "\n");
} }
if (len >= PAGE_SIZE)
return PAGE_SIZE;
return len; return len;
} }
CPUFREQ_STATDEVICE_ATTR(trans_table,0444,show_trans_table); CPUFREQ_STATDEVICE_ATTR(trans_table,0444,show_trans_table);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment