Skip to content

Commit bbec2a2

Browse files
committed
Merge tag 'pm-5.7-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull more power management updates from Rafael Wysocki: "Rework compat ioctl handling in the user space hibernation interface (Christoph Hellwig) and fix a typo in a function name in the cpuidle haltpoll driver (Yihao Wu)" * tag 'pm-5.7-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: cpuidle-haltpoll: Fix small typo PM / sleep: handle the compat case in snapshot_set_swap_area() PM / sleep: move SNAPSHOT_SET_SWAP_AREA handling into a helper
2 parents 523a05f + a31434b commit bbec2a2

File tree

2 files changed

+48
-57
lines changed

2 files changed

+48
-57
lines changed

drivers/cpuidle/cpuidle-haltpoll.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void haltpoll_uninit(void)
9494
haltpoll_cpuidle_devices = NULL;
9595
}
9696

97-
static bool haltpool_want(void)
97+
static bool haltpoll_want(void)
9898
{
9999
return kvm_para_has_hint(KVM_HINTS_REALTIME) || force;
100100
}
@@ -110,7 +110,7 @@ static int __init haltpoll_init(void)
110110

111111
cpuidle_poll_state_init(drv);
112112

113-
if (!kvm_para_available() || !haltpool_want())
113+
if (!kvm_para_available() || !haltpoll_want())
114114
return -ENODEV;
115115

116116
ret = cpuidle_register_driver(drv);

kernel/power/user.c

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

199+
struct compat_resume_swap_area {
200+
compat_loff_t offset;
201+
u32 dev;
202+
} __packed;
203+
204+
static int snapshot_set_swap_area(struct snapshot_data *data,
205+
void __user *argp)
206+
{
207+
sector_t offset;
208+
dev_t swdev;
209+
210+
if (swsusp_swap_in_use())
211+
return -EPERM;
212+
213+
if (in_compat_syscall()) {
214+
struct compat_resume_swap_area swap_area;
215+
216+
if (copy_from_user(&swap_area, argp, sizeof(swap_area)))
217+
return -EFAULT;
218+
swdev = new_decode_dev(swap_area.dev);
219+
offset = swap_area.offset;
220+
} else {
221+
struct resume_swap_area swap_area;
222+
223+
if (copy_from_user(&swap_area, argp, sizeof(swap_area)))
224+
return -EFAULT;
225+
swdev = new_decode_dev(swap_area.dev);
226+
offset = swap_area.offset;
227+
}
228+
229+
/*
230+
* User space encodes device types as two-byte values,
231+
* so we need to recode them
232+
*/
233+
if (!swdev) {
234+
data->swap = -1;
235+
return -EINVAL;
236+
}
237+
data->swap = swap_type_of(swdev, offset, NULL);
238+
if (data->swap < 0)
239+
return -ENODEV;
240+
return 0;
241+
}
242+
199243
static long snapshot_ioctl(struct file *filp, unsigned int cmd,
200244
unsigned long arg)
201245
{
@@ -351,34 +395,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
351395
break;
352396

353397
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-
}
398+
error = snapshot_set_swap_area(data, (void __user *)arg);
382399
break;
383400

384401
default:
@@ -393,12 +410,6 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
393410
}
394411

395412
#ifdef CONFIG_COMPAT
396-
397-
struct compat_resume_swap_area {
398-
compat_loff_t offset;
399-
u32 dev;
400-
} __packed;
401-
402413
static long
403414
snapshot_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
404415
{
@@ -409,33 +420,13 @@ snapshot_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
409420
case SNAPSHOT_AVAIL_SWAP_SIZE:
410421
case SNAPSHOT_ALLOC_SWAP_PAGE:
411422
case SNAPSHOT_CREATE_IMAGE:
423+
case SNAPSHOT_SET_SWAP_AREA:
412424
return snapshot_ioctl(file, cmd,
413425
(unsigned long) compat_ptr(arg));
414-
415-
case SNAPSHOT_SET_SWAP_AREA: {
416-
struct compat_resume_swap_area __user *u_swap_area =
417-
compat_ptr(arg);
418-
struct resume_swap_area swap_area;
419-
mm_segment_t old_fs;
420-
int err;
421-
422-
err = get_user(swap_area.offset, &u_swap_area->offset);
423-
err |= get_user(swap_area.dev, &u_swap_area->dev);
424-
if (err)
425-
return -EFAULT;
426-
old_fs = get_fs();
427-
set_fs(KERNEL_DS);
428-
err = snapshot_ioctl(file, SNAPSHOT_SET_SWAP_AREA,
429-
(unsigned long) &swap_area);
430-
set_fs(old_fs);
431-
return err;
432-
}
433-
434426
default:
435427
return snapshot_ioctl(file, cmd, arg);
436428
}
437429
}
438-
439430
#endif /* CONFIG_COMPAT */
440431

441432
static const struct file_operations snapshot_fops = {

0 commit comments

Comments
 (0)