Skip to content

Commit

Permalink
PM / sleep: move SNAPSHOT_SET_SWAP_AREA handling into a helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christoph Hellwig authored and Rafael J. Wysocki committed Apr 6, 2020
1 parent 7e63420 commit 88a7755
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions kernel/power/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,34 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
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)
{
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 88a7755

Please sign in to comment.