mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
hrtimer: Rework hrtimer_nanosleep to make sys_compat_nanosleep easier
Pull the copy_to_user out of hrtimer_nanosleep and into the callers (common_nsleep, sys_nanosleep) in preparation for converting compat_sys_nanosleep to use hrtimers. Signed-off-by: Anton Blanchard <anton@samba.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
parent
d85714d81c
commit
04c227140f
3 changed files with 31 additions and 17 deletions
|
@ -300,7 +300,7 @@ hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
|
||||||
|
|
||||||
/* Precise sleep: */
|
/* Precise sleep: */
|
||||||
extern long hrtimer_nanosleep(struct timespec *rqtp,
|
extern long hrtimer_nanosleep(struct timespec *rqtp,
|
||||||
struct timespec __user *rmtp,
|
struct timespec *rmtp,
|
||||||
const enum hrtimer_mode mode,
|
const enum hrtimer_mode mode,
|
||||||
const clockid_t clockid);
|
const clockid_t clockid);
|
||||||
extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
|
extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
|
||||||
|
|
|
@ -1286,8 +1286,7 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod
|
||||||
long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
|
long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
|
||||||
{
|
{
|
||||||
struct hrtimer_sleeper t;
|
struct hrtimer_sleeper t;
|
||||||
struct timespec __user *rmtp;
|
struct timespec *rmtp;
|
||||||
struct timespec tu;
|
|
||||||
ktime_t time;
|
ktime_t time;
|
||||||
|
|
||||||
restart->fn = do_no_restart_syscall;
|
restart->fn = do_no_restart_syscall;
|
||||||
|
@ -1298,14 +1297,12 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
|
||||||
if (do_nanosleep(&t, HRTIMER_MODE_ABS))
|
if (do_nanosleep(&t, HRTIMER_MODE_ABS))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rmtp = (struct timespec __user *) restart->arg1;
|
rmtp = (struct timespec *)restart->arg1;
|
||||||
if (rmtp) {
|
if (rmtp) {
|
||||||
time = ktime_sub(t.timer.expires, t.timer.base->get_time());
|
time = ktime_sub(t.timer.expires, t.timer.base->get_time());
|
||||||
if (time.tv64 <= 0)
|
if (time.tv64 <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
tu = ktime_to_timespec(time);
|
*rmtp = ktime_to_timespec(time);
|
||||||
if (copy_to_user(rmtp, &tu, sizeof(tu)))
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
restart->fn = hrtimer_nanosleep_restart;
|
restart->fn = hrtimer_nanosleep_restart;
|
||||||
|
@ -1314,12 +1311,11 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
|
||||||
return -ERESTART_RESTARTBLOCK;
|
return -ERESTART_RESTARTBLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
|
long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp,
|
||||||
const enum hrtimer_mode mode, const clockid_t clockid)
|
const enum hrtimer_mode mode, const clockid_t clockid)
|
||||||
{
|
{
|
||||||
struct restart_block *restart;
|
struct restart_block *restart;
|
||||||
struct hrtimer_sleeper t;
|
struct hrtimer_sleeper t;
|
||||||
struct timespec tu;
|
|
||||||
ktime_t rem;
|
ktime_t rem;
|
||||||
|
|
||||||
hrtimer_init(&t.timer, clockid, mode);
|
hrtimer_init(&t.timer, clockid, mode);
|
||||||
|
@ -1335,9 +1331,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
|
||||||
rem = ktime_sub(t.timer.expires, t.timer.base->get_time());
|
rem = ktime_sub(t.timer.expires, t.timer.base->get_time());
|
||||||
if (rem.tv64 <= 0)
|
if (rem.tv64 <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
tu = ktime_to_timespec(rem);
|
*rmtp = ktime_to_timespec(rem);
|
||||||
if (copy_to_user(rmtp, &tu, sizeof(tu)))
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
restart = ¤t_thread_info()->restart_block;
|
restart = ¤t_thread_info()->restart_block;
|
||||||
|
@ -1353,7 +1347,8 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
|
||||||
asmlinkage long
|
asmlinkage long
|
||||||
sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
|
sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
|
||||||
{
|
{
|
||||||
struct timespec tu;
|
struct timespec tu, rmt;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (copy_from_user(&tu, rqtp, sizeof(tu)))
|
if (copy_from_user(&tu, rqtp, sizeof(tu)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
@ -1361,7 +1356,15 @@ sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
|
||||||
if (!timespec_valid(&tu))
|
if (!timespec_valid(&tu))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
|
ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL,
|
||||||
|
CLOCK_MONOTONIC);
|
||||||
|
|
||||||
|
if (ret && rmtp) {
|
||||||
|
if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -981,9 +981,20 @@ sys_clock_getres(const clockid_t which_clock, struct timespec __user *tp)
|
||||||
static int common_nsleep(const clockid_t which_clock, int flags,
|
static int common_nsleep(const clockid_t which_clock, int flags,
|
||||||
struct timespec *tsave, struct timespec __user *rmtp)
|
struct timespec *tsave, struct timespec __user *rmtp)
|
||||||
{
|
{
|
||||||
return hrtimer_nanosleep(tsave, rmtp, flags & TIMER_ABSTIME ?
|
struct timespec rmt;
|
||||||
HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
|
int ret;
|
||||||
which_clock);
|
|
||||||
|
ret = hrtimer_nanosleep(tsave, rmtp ? &rmt : NULL,
|
||||||
|
flags & TIMER_ABSTIME ?
|
||||||
|
HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
|
||||||
|
which_clock);
|
||||||
|
|
||||||
|
if (ret && rmtp) {
|
||||||
|
if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
asmlinkage long
|
asmlinkage long
|
||||||
|
|
Loading…
Reference in a new issue