Skip to content

Commit 88a7755

Browse files
Christoph Hellwigrafaeljw
authored andcommitted
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 <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 7e63420 commit 88a7755

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

kernel/power/user.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,34 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
196196
return res;
197197
}
198198

199+
static int snapshot_set_swap_area(struct snapshot_data *data,
200+
void __user *argp)
201+
{
202+
struct resume_swap_area swap_area;
203+
sector_t offset;
204+
dev_t swdev;
205+
206+
if (swsusp_swap_in_use())
207+
return -EPERM;
208+
if (copy_from_user(&swap_area, argp, sizeof(swap_area)))
209+
return -EFAULT;
210+
211+
/*
212+
* User space encodes device types as two-byte values,
213+
* so we need to recode them
214+
*/
215+
swdev = new_decode_dev(swap_area.dev);
216+
if (!swdev) {
217+
data->swap = -1;
218+
return -EINVAL;
219+
}
220+
offset = swap_area.offset;
221+
data->swap = swap_type_of(swdev, offset, NULL);
222+
if (data->swap < 0)
223+
return -ENODEV;
224+
return 0;
225+
}
226+
199227
static long snapshot_ioctl(struct file *filp, unsigned int cmd,
200228
unsigned long arg)
201229
{
@@ -351,34 +379,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
351379
break;
352380

353381
case SNAPSHOT_SET_SWAP_AREA:
354-
if (swsusp_swap_in_use()) {
355-
error = -EPERM;
356-
} else {
357-
struct resume_swap_area swap_area;
358-
dev_t swdev;
359-
360-
error = copy_from_user(&swap_area, (void __user *)arg,
361-
sizeof(struct resume_swap_area));
362-
if (error) {
363-
error = -EFAULT;
364-
break;
365-
}
366-
367-
/*
368-
* User space encodes device types as two-byte values,
369-
* so we need to recode them
370-
*/
371-
swdev = new_decode_dev(swap_area.dev);
372-
if (swdev) {
373-
offset = swap_area.offset;
374-
data->swap = swap_type_of(swdev, offset, NULL);
375-
if (data->swap < 0)
376-
error = -ENODEV;
377-
} else {
378-
data->swap = -1;
379-
error = -EINVAL;
380-
}
381-
}
382+
error = snapshot_set_swap_area(data, (void __user *)arg);
382383
break;
383384

384385
default:

0 commit comments

Comments
 (0)