2015-04-30 08:12:48

by Baolin Wang

[permalink] [raw]
Subject: [PATCH v2 05/15] posix-timers:Split out the guts of the syscall and change the implementation

This patch splits out the guts of the syscall and changes the syscall
implementation to prepare the converting to 64bit methods for the syscall
function in posix-timers.c file. And next patch will convert the syscall
to 64bit methods with timespec64/itimerspec64 type.

Signed-off-by: Baolin Wang <[email protected]>
---
kernel/time/posix-timers.c | 107 +++++++++++++++++++++++++++++---------------
1 file changed, 71 insertions(+), 36 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 31ea01f..0db7f02 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -766,11 +766,8 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
cur_setting->it_value = ktime_to_timespec(remaining);
}

-/* Get the time remaining on a POSIX.1b interval timer. */
-SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
- struct itimerspec __user *, setting)
+static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting)
{
- struct itimerspec cur_setting;
struct k_itimer *timr;
struct k_clock *kc;
unsigned long flags;
@@ -784,9 +781,18 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
if (WARN_ON_ONCE(!kc || !kc->timer_get))
ret = -EINVAL;
else
- kc->timer_get(timr, &cur_setting);
+ kc->timer_get(timr, cur_setting);

unlock_timer(timr, flags);
+ return ret;
+}
+
+/* Get the time remaining on a POSIX.1b interval timer. */
+SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
+ struct itimerspec __user *, setting)
+{
+ struct itimerspec cur_setting;
+ int ret = __timer_gettime(timer_id, &cur_setting);

if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
return -EFAULT;
@@ -870,27 +876,14 @@ common_timer_set(struct k_itimer *timr, int flags,
return 0;
}

-/* Set a POSIX.1b interval timer */
-SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
- const struct itimerspec __user *, new_setting,
- struct itimerspec __user *, old_setting)
+static int __timer_settime(timer_t timer_id, int flags, struct itimerspec *new_spec,
+ struct itimerspec *old_spec)
{
struct k_itimer *timr;
- struct itimerspec new_spec, old_spec;
int error = 0;
unsigned long flag;
- struct itimerspec *rtn = old_setting ? &old_spec : NULL;
struct k_clock *kc;

- if (!new_setting)
- return -EINVAL;
-
- if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
- return -EFAULT;
-
- if (!timespec_valid(&new_spec.it_interval) ||
- !timespec_valid(&new_spec.it_value))
- return -EINVAL;
retry:
timr = lock_timer(timer_id, &flag);
if (!timr)
@@ -900,14 +893,38 @@ retry:
if (WARN_ON_ONCE(!kc || !kc->timer_set))
error = -EINVAL;
else
- error = kc->timer_set(timr, flags, &new_spec, rtn);
+ error = kc->timer_set(timr, flags, new_spec, old_spec);

unlock_timer(timr, flag);
if (error == TIMER_RETRY) {
- rtn = NULL; // We already got the old time...
+ old_spec = NULL; // We already got the old time...
goto retry;
}

+ return error;
+}
+
+/* Set a POSIX.1b interval timer */
+SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
+ const struct itimerspec __user *, new_setting,
+ struct itimerspec __user *, old_setting)
+{
+ struct itimerspec new_spec, old_spec;
+ int error = 0;
+ struct itimerspec *rtn = old_setting ? &old_spec : NULL;
+
+ if (!new_setting)
+ return -EINVAL;
+
+ if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
+ return -EFAULT;
+
+ if (!timespec_valid(&new_spec.it_interval) ||
+ !timespec_valid(&new_spec.it_value))
+ return -EINVAL;
+
+ error = __timer_settime(timer_id, flags, &new_spec, rtn);
+
if (old_setting && !error &&
copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
error = -EFAULT;
@@ -1002,32 +1019,44 @@ void exit_itimers(struct signal_struct *sig)
}
}

-SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
- const struct timespec __user *, tp)
+static int __clock_settime(clockid_t which_clock, struct timespec *ts)
{
struct k_clock *kc = clockid_to_kclock(which_clock);
- struct timespec new_tp;

if (!kc || !kc->clock_set)
return -EINVAL;

+ return kc->clock_set(which_clock, ts);
+}
+
+SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
+ const struct timespec __user *, tp)
+{
+ struct timespec new_tp;
+
if (copy_from_user(&new_tp, tp, sizeof (*tp)))
return -EFAULT;

- return kc->clock_set(which_clock, &new_tp);
+ return __clock_settime(which_clock, &new_tp);
}

-SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
- struct timespec __user *,tp)
+static int __clock_gettime(clockid_t which_clock, struct timespec *ts)
{
struct k_clock *kc = clockid_to_kclock(which_clock);
- struct timespec kernel_tp;
- int error;

if (!kc)
return -EINVAL;

- error = kc->clock_get(which_clock, &kernel_tp);
+ return kc->clock_get(which_clock, ts);
+}
+
+SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
+ struct timespec __user *,tp)
+{
+ struct timespec kernel_tp;
+ int error;
+
+ error = __clock_gettime(which_clock, &kernel_tp);

if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
error = -EFAULT;
@@ -1058,17 +1087,23 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
return err;
}

-SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
- struct timespec __user *, tp)
+static int __clock_getres(clockid_t which_clock, struct timespec *ts)
{
struct k_clock *kc = clockid_to_kclock(which_clock);
- struct timespec rtn_tp;
- int error;

if (!kc)
return -EINVAL;

- error = kc->clock_getres(which_clock, &rtn_tp);
+ return kc->clock_getres(which_clock, ts);
+}
+
+SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
+ struct timespec __user *, tp)
+{
+ struct timespec rtn_tp;
+ int error;
+
+ error = __clock_getres(which_clock, &rtn_tp);

if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
error = -EFAULT;
--
1.7.9.5