summaryrefslogtreecommitdiff
path: root/kernel/power
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-04-06 13:58:34 +0200
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2020-04-06 21:42:36 +0200
commit88a77559cc06f4a80e956dbf2da2a33c5f18c0af (patch)
tree3fd2ad33e7db9a4b48a314efc71f3d3726b2cf6b /kernel/power
parent7e63420847ae5f1036e4f7c42f0b3282e73efbc2 (diff)
PM / sleep: move SNAPSHOT_SET_SWAP_AREA handling into a helper
Move the handling of the SNAPSHOT_SET_SWAP_AREA ioctl from the main ioctl helper into a helper function. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'kernel/power')
-rw-r--r--kernel/power/user.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/kernel/power/user.c b/kernel/power/user.c
index ef90eb1fb86e..0cb555f526e4 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -196,6 +196,34 @@ unlock:
return res;
}
+static int snapshot_set_swap_area(struct snapshot_data *data,
+ void __user *argp)
+{
+ struct resume_swap_area swap_area;
+ sector_t offset;
+ dev_t swdev;
+
+ if (swsusp_swap_in_use())
+ return -EPERM;
+ if (copy_from_user(&swap_area, argp, sizeof(swap_area)))
+ return -EFAULT;
+
+ /*
+ * User space encodes device types as two-byte values,
+ * so we need to recode them
+ */
+ swdev = new_decode_dev(swap_area.dev);
+ if (!swdev) {
+ data->swap = -1;
+ return -EINVAL;
+ }
+ offset = swap_area.offset;
+ data->swap = swap_type_of(swdev, offset, NULL);
+ if (data->swap < 0)
+ return -ENODEV;
+ return 0;
+}
+
static long snapshot_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
@@ -351,34 +379,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
break;
case SNAPSHOT_SET_SWAP_AREA:
- if (swsusp_swap_in_use()) {
- error = -EPERM;
- } else {
- struct resume_swap_area swap_area;
- dev_t swdev;
-
- error = copy_from_user(&swap_area, (void __user *)arg,
- sizeof(struct resume_swap_area));
- if (error) {
- error = -EFAULT;
- break;
- }
-
- /*
- * User space encodes device types as two-byte values,
- * so we need to recode them
- */
- swdev = new_decode_dev(swap_area.dev);
- if (swdev) {
- offset = swap_area.offset;
- data->swap = swap_type_of(swdev, offset, NULL);
- if (data->swap < 0)
- error = -ENODEV;
- } else {
- data->swap = -1;
- error = -EINVAL;
- }
- }
+ error = snapshot_set_swap_area(data, (void __user *)arg);
break;
default: