time/posix-timers: Move the compat copyouts to the nanosleep implementations

Turn restart_block.nanosleep.{rmtp,compat_rmtp} into a tagged union (kind =
1 -> native, kind = 2 -> compat, kind = 0 -> nothing) and make the places
doing actual copyout handle compat as well as native (that will become a
helper in the next commit).  Result: compat wrappers, messing with
reassignments, etc. are gone.

[ tglx: Folded in a variant of Peter Zijlstras enum patch ]

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20170607084241.28657-6-viro@ZenIV.linux.org.uk
This commit is contained in:
Al Viro 2017-06-07 09:42:31 +01:00 committed by Thomas Gleixner
parent 99e6c0e6ec
commit edbeda4632
8 changed files with 142 additions and 171 deletions

View file

@ -12,6 +12,7 @@
#include <trace/events/timer.h>
#include <linux/tick.h>
#include <linux/workqueue.h>
#include <linux/compat.h>
#include "posix-timers.h"
@ -1243,10 +1244,9 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
timer.it_process = current;
if (!error) {
static struct itimerspec64 zero_it;
struct restart_block *restart = &current->restart_block;
struct timespec __user *rmtp;
struct restart_block *restart;
memset(&it, 0, sizeof it);
memset(&it, 0, sizeof(it));
it.it_value = *rqtp;
spin_lock_irq(&timer.it_lock);
@ -1311,12 +1311,20 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
/*
* Report back to the user the time still remaining.
*/
rmtp = restart->nanosleep.rmtp;
if (rmtp) {
restart = &current->restart_block;
if (restart->nanosleep.type != TT_NONE) {
struct timespec ts;
ts = timespec64_to_timespec(it.it_value);
if (copy_to_user(rmtp, &ts, sizeof(*rmtp)))
#ifdef CONFIG_COMPAT
if (restart->nanosleep.type == TT_COMPAT) {
if (compat_put_timespec(&ts,
restart->nanosleep.compat_rmtp))
return -EFAULT;
} else
#endif
if (copy_to_user(restart->nanosleep.rmtp, &ts,
sizeof(ts)))
return -EFAULT;
}
restart->nanosleep.expires = timespec64_to_ns(rqtp);