From e9b6dfb709cdc1d5521fed7dff73bc8fa71e1425 Mon Sep 17 00:00:00 2001 From: Mahesh Sivasubramanian Date: Mon, 4 Jun 2012 17:45:29 -0600 Subject: [PATCH] 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 --- arch/arm/mach-msm/pm-stats.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-msm/pm-stats.c b/arch/arm/mach-msm/pm-stats.c index 936820a9a2c..675febb47b1 100644 --- a/arch/arm/mach-msm/pm-stats.c +++ b/arch/arm/mach-msm/pm-stats.c @@ -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; }