Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753637AbbF2O1P (ORCPT ); Mon, 29 Jun 2015 10:27:15 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36349 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752685AbbF2O02 (ORCPT ); Mon, 29 Jun 2015 10:26:28 -0400 From: Bamvor Zhang Jian To: arnd@arndb.de, john.stultz@linaro.org, tglx@linutronix.de Cc: y2039@lists.linaro.org, linux-kernel@vger.kernel.org, bamvor.zhangjian@linaro.org Subject: [RFC PATCH v2 2/4] time64: add timeval64 helper for compat syscalls Date: Mon, 29 Jun 2015 22:23:25 +0800 Message-Id: <1435587807-10008-3-git-send-email-bamvor.zhangjian@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435587807-10008-1-git-send-email-bamvor.zhangjian@linaro.org> References: <1435587807-10008-1-git-send-email-bamvor.zhangjian@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3056 Lines: 81 Add __kernel_compat_timeval in uapi in order to use it in ioctl command because compat_timeval is invisible in uapi. Meanwhile We could avoid to define it by using the __s32 array in ioctl command definition. I am sure which one is the better way. Any suggestion or input is welcome. This patch also define compat_get_timeval64, compat_put_timeval64 for converting between compat_timeval and timeval64. Signed-off-by: Bamvor Zhang Jian --- include/linux/compat.h | 3 +++ include/uapi/linux/time.h | 6 ++++++ kernel/compat.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/linux/compat.h b/include/linux/compat.h index ab25814..14569a7 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -154,6 +154,9 @@ extern int compat_get_timespec(struct timespec *, const void __user *); extern int compat_put_timespec(const struct timespec *, void __user *); extern int compat_get_timeval(struct timeval *, const void __user *); extern int compat_put_timeval(const struct timeval *, void __user *); +struct timeval64; +extern int compat_get_timeval64(struct timeval64 *tv, const struct compat_timeval __user *ctv); +extern int compat_put_timeval64(const struct timeval64 *tv, struct compat_timeval __user *ctv); /* * This function convert a timespec if necessary and returns a *user diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 2ca6a31..9f6093e 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -76,4 +76,10 @@ struct __kernel_timeval { }; #endif +typedef __s32 __kernel_time32_t; +struct __kernel_compat_timeval { + __kernel_time32_t tv_sec; + __s32 tv_usec; +}; + #endif /* _UAPI_LINUX_TIME_H */ diff --git a/kernel/compat.c b/kernel/compat.c index 333d364..ebe45b4 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -172,6 +172,23 @@ int compat_put_timeval(const struct timeval *tv, void __user *utv) } EXPORT_SYMBOL_GPL(compat_put_timeval); +int compat_get_timeval64(struct timeval64 *tv, const struct compat_timeval __user *ctv) +{ + return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) || + __get_user(tv->tv_sec, &ctv->tv_sec) || + __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0; +} +EXPORT_SYMBOL_GPL(compat_get_timeval64); + +/* TODO: is it ok that just put to user without implicit cast? */ +int compat_put_timeval64(const struct timeval64 *tv, struct compat_timeval *ctv) +{ + return (!access_ok(VERIFY_WRITE, ctv, sizeof(*ctv)) || + __put_user(tv->tv_sec, &ctv->tv_sec) || + __put_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0; +} +EXPORT_SYMBOL_GPL(compat_put_timeval64); + int compat_get_timespec(struct timespec *ts, const void __user *uts) { if (COMPAT_USE_64BIT_TIME) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/