swsusp: fix sysfs interface

The sysfs files /sys/power/disk and /sys/power/state do not work as
documented, since they allow the user to write only a few initial
characters of the input string to trigger the option (eg. 'echo pl >
/sys/power/disk' activates the platform mode of hibernation). Fix it.

Special thanks to Peter Moulder <Peter.Moulder@infotech.monash.edu.au> for
pointing out the problem.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Rafael J. Wysocki and committed by Linus Torvalds 8d98a690 7925409e

+4 -3
+2 -1
kernel/power/disk.c
··· 416 416 417 417 mutex_lock(&pm_mutex); 418 418 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) { 419 - if (!strncmp(buf, hibernation_modes[i], len)) { 419 + if (len == strlen(hibernation_modes[i]) 420 + && !strncmp(buf, hibernation_modes[i], len)) { 420 421 mode = i; 421 422 break; 422 423 }
+2 -2
kernel/power/main.c
··· 290 290 len = p ? p - buf : n; 291 291 292 292 /* First, check if we are requested to hibernate */ 293 - if (!strncmp(buf, "disk", len)) { 293 + if (len == 4 && !strncmp(buf, "disk", len)) { 294 294 error = hibernate(); 295 295 return error ? error : n; 296 296 } 297 297 298 298 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { 299 - if (*s && !strncmp(buf, *s, len)) 299 + if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) 300 300 break; 301 301 } 302 302 if (state < PM_SUSPEND_MAX && *s)