Skip to contentSkip to conversation

PM: Fix sysfs interface

PATCH In review Rafael J. Wysocki 2 participants 3 messages May 11, 2007 – May 14, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: Fix sysfs interface

From: Rafael J. Wysocki <[email protected]>

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.

---
 kernel/power/disk.c |    3 ++-
 kernel/power/main.c |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
kernel/power/disk.c +2 -1
Index: 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;
 		}
kernel/power/main.c +2 -2
Index: 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)
#1 lore raw

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

---
From: Rafael J. Wysocki <[email protected]>

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.

 kernel/power/disk.c |    3 ++-
 kernel/power/main.c |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
kernel/power/disk.c +2 -1
Index: 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;
 		}
kernel/power/main.c +2 -2
Index: 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)
Signature · 3 lines
If you don't have the time to read,
you don't have the time or the tools to write.
		- Stephen King
#2 lore raw
Quoted 10 lines · Rafael J. Wysocki

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

---
From: Rafael J. Wysocki <[email protected]>

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.

Quoted 4 lines

Special thanks to Peter Moulder <[email protected]> for pointing out the problem.

ACK.
Pavel

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