Skip to content

Commit

Permalink
swsusp: fix sysfs interface
Browse files Browse the repository at this point in the history
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 <[email protected]> for
pointing out the problem.

Signed-off-by: Rafael J. Wysocki <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rjwysocki authored and Linus Torvalds committed May 17, 2007
1 parent 7925409 commit 8d98a69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kernel/power/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ static ssize_t disk_store(struct kset *kset, const char *buf, size_t n)

mutex_lock(&pm_mutex);
for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
if (!strncmp(buf, hibernation_modes[i], len)) {
if (len == strlen(hibernation_modes[i])
&& !strncmp(buf, hibernation_modes[i], len)) {
mode = i;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/power/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ static ssize_t state_store(struct kset *kset, const char *buf, size_t n)
len = p ? p - buf : n;

/* First, check if we are requested to hibernate */
if (!strncmp(buf, "disk", len)) {
if (len == 4 && !strncmp(buf, "disk", len)) {
error = hibernate();
return error ? error : n;
}

for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
if (*s && !strncmp(buf, *s, len))
if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
break;
}
if (state < PM_SUSPEND_MAX && *s)
Expand Down

0 comments on commit 8d98a69

Please sign in to comment.