swsusp: Fix userland interface
authorRafael J. Wysocki <rjw@sisk.pl>
Sat, 16 Jun 2007 17:16:03 +0000 (10:16 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Sat, 16 Jun 2007 20:16:15 +0000 (13:16 -0700)
Fix oops caused by 'cat /dev/snapshot', reported by Arkadiusz Miskiewicz,
and make it impossible to thaw tasks with the help of the swsusp userland
interface while there is a snapshot image ready to save.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/power/user.c

index 24d7d78e6f42ff71e95401b82460924709346f1a..d65305b515b1ec8c359532b3f29812178fbbb6ad 100644 (file)
@@ -99,6 +99,8 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
        ssize_t res;
 
        data = filp->private_data;
+       if (!data->ready)
+               return -ENODATA;
        res = snapshot_read_next(&data->handle, count);
        if (res > 0) {
                if (copy_to_user(buf, data_of(data->handle), res))
@@ -245,7 +247,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                break;
 
        case SNAPSHOT_UNFREEZE:
-               if (!data->frozen)
+               if (!data->frozen || data->ready)
                        break;
                mutex_lock(&pm_mutex);
                thaw_processes();