public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PM: Fix sysfs interface
@ 2007-05-11  9:58 Rafael J. Wysocki
  2007-05-11 10:13 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2007-05-11  9:58 UTC (permalink / raw)
  To: pm list; +Cc: Peter Moulder, Johannes Berg, Pavel Machek

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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PM: Fix sysfs interface
  2007-05-11  9:58 [PATCH] PM: Fix sysfs interface Rafael J. Wysocki
@ 2007-05-11 10:13 ` Rafael J. Wysocki
  2007-05-14  9:18   ` Pavel Machek
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2007-05-11 10:13 UTC (permalink / raw)
  To: linux-pm; +Cc: Peter Moulder, Johannes Berg, Pavel Machek

Sorry, there's a mistake in the previous version.  Corrected patch follows.

---
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	2007-05-11 12:06:28.000000000 +0200
+++ linux-2.6.21/kernel/power/disk.c	2007-05-11 12:06:33.000000000 +0200
@@ -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	2007-05-11 12:06:28.000000000 +0200
+++ linux-2.6.21/kernel/power/main.c	2007-05-11 12:07:02.000000000 +0200
@@ -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)
-- 
If you don't have the time to read,
you don't have the time or the tools to write.
		- Stephen King

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PM: Fix sysfs interface
  2007-05-11 10:13 ` Rafael J. Wysocki
@ 2007-05-14  9:18   ` Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2007-05-14  9:18 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Johannes Berg, linux-pm, Peter Moulder

On Fri 2007-05-11 12:13:30, Rafael J. Wysocki wrote:
> Sorry, there's a mistake in the previous version.  Corrected patch follows.
> 
> ---
> 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>

ACK.
									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-14  9:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-11  9:58 [PATCH] PM: Fix sysfs interface Rafael J. Wysocki
2007-05-11 10:13 ` Rafael J. Wysocki
2007-05-14  9:18   ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox