msm: pm-stats: Fix bug in computing size of a string

Use strlen and strcmp instead of sizeof and memcmp to compare strings.
procfs includes the newline character as a part of the buffer. When
using sizeof and memcmp, the newline character is used in the comparison
resulting in unequal bufferes.

Change-Id: Iafce2543596708e28757805cecae1ccec083c691
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
This commit is contained in:
Mahesh Sivasubramanian
2012-06-04 17:45:29 -06:00
committed by Stephen Boyd
parent dcd23d119c
commit e9b6dfb709

View File

@@ -188,18 +188,19 @@ static int msm_pm_write_proc(struct file *file, const char __user *buffer,
int ret;
unsigned long flags;
unsigned int cpu;
size_t len = strnlen(MSM_PM_STATS_RESET, sizeof(MSM_PM_STATS_RESET));
if (count < sizeof(MSM_PM_STATS_RESET)) {
ret = -EINVAL;
goto write_proc_failed;
}
if (copy_from_user(buf, buffer, sizeof(MSM_PM_STATS_RESET))) {
if (copy_from_user(buf, buffer, len)) {
ret = -EFAULT;
goto write_proc_failed;
}
if (memcmp(buf, MSM_PM_STATS_RESET, sizeof(MSM_PM_STATS_RESET))) {
if (strncmp(buf, MSM_PM_STATS_RESET, len)) {
ret = -EINVAL;
goto write_proc_failed;
}