Skip to contentSkip to conversation

swsusp: Fix possible oops in userland interface

PATCH New Rafael J. Wysocki 1 participant 1 message Feb 6, 2007

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

PATCH 1/1 swsusp: Fix possible oops in userland interface

The SNAPSHOT_PMOPS and SNAPSHOT_S2RAM ioctls can Oops if they are called from a kernel that doesn't set pm_ops (eg. non-ACPI kernel on a PC). Fix it.

---
 kernel/power/user.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
kernel/power/user.c +11 -2
Index: linux-2.6.20-rc6-mm3/kernel/power/user.c
===================================================================
@@ -341,6 +341,11 @@ static int snapshot_ioctl(struct inode *
 		break;
 
 	case SNAPSHOT_S2RAM:
+		if (!pm_ops) {
+			error = -ENOSYS;
+			break;
+		}
+
 		if (!data->frozen) {
 			error = -EPERM;
 			break;
@@ -383,8 +388,12 @@ static int snapshot_ioctl(struct inode *
 		switch (arg) {
 
 		case PMOPS_PREPARE:
-			data->platform_suspend = 1;
-			error = 0;
+			if (pm_ops && pm_ops->enter) {
+				data->platform_suspend = 1;
+				error = 0;
+			} else {
+				error = -ENOSYS;
+			}
 			break;
 
 		case PMOPS_ENTER: