public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: pm list <linux-pm@lists.linux-foundation.org>
Cc: Peter Moulder <Peter.Moulder@infotech.monash.edu.au>,
	Johannes Berg <johannes@sipsolutions.net>,
	Pavel Machek <pavel@ucw.cz>
Subject: [PATCH] PM: Fix sysfs interface
Date: Fri, 11 May 2007 11:58:44 +0200	[thread overview]
Message-ID: <200705111158.44913.rjw@sisk.pl> (raw)

From: Rafael J. Wysocki <rjw@sisk.pl>

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>
---
 kernel/power/disk.c |    3 ++-
 kernel/power/main.c |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

Index: linux-2.6.21/kernel/power/disk.c
===================================================================
--- linux-2.6.21.orig/kernel/power/disk.c
+++ linux-2.6.21/kernel/power/disk.c
@@ -416,7 +416,8 @@ static ssize_t disk_store(struct subsyst
 
 	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;
 		}
Index: linux-2.6.21/kernel/power/main.c
===================================================================
--- linux-2.6.21.orig/kernel/power/main.c
+++ linux-2.6.21/kernel/power/main.c
@@ -289,13 +289,13 @@ static ssize_t state_store(struct subsys
 	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)

             reply	other threads:[~2007-05-11  9:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-11  9:58 Rafael J. Wysocki [this message]
2007-05-11 10:13 ` [PATCH] PM: Fix sysfs interface Rafael J. Wysocki
2007-05-14  9:18   ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200705111158.44913.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=Peter.Moulder@infotech.monash.edu.au \
    --cc=johannes@sipsolutions.net \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox