From patchwork Sat Jan 7 12:01:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yuan linyu X-Patchwork-Id: 9503005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F3BC606E0 for ; Sat, 7 Jan 2017 12:01:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 057CD201BC for ; Sat, 7 Jan 2017 12:01:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDF79284B1; Sat, 7 Jan 2017 12:01:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4FCC201BC for ; Sat, 7 Jan 2017 12:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936987AbdAGMBo (ORCPT ); Sat, 7 Jan 2017 07:01:44 -0500 Received: from m12-18.163.com ([220.181.12.18]:42074 "EHLO m12-18.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932474AbdAGMBn (ORCPT ); Sat, 7 Jan 2017 07:01:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=DD6hm 9X/v3DPruLA/RoC+CYfbYr/EBPsKTK2ONtCSjY=; b=PybjzSuWODdykVhdeORod Sn04ayvFuJ0e/1xd5ZqTMicJqVzE9DCnN+7HGpZMaMw2TwdSs/OeR3E/68IPETGi Em75VfAEmo4qmktd5oQE4LLfqq9F37Q8Wj2wpudBrr4bKbmFxVvOmsqHSoNbQi68 M556gvZ9Nyrsi84mvQpEEI= Received: from localhost.localdomain (unknown [220.179.147.21]) by smtp14 (Coremail) with SMTP id EsCowACnwciX2HBYz+73HA--.31913S2; Sat, 07 Jan 2017 20:01:28 +0800 (CST) From: yuan linyu To: linux-fsdevel@vger.kernel.org Cc: Alexander Viro , yuan linyu Subject: [PATCH] fs: rename poll_select_set_timeout() to set_normalized_timeout() Date: Sat, 7 Jan 2017 20:01:15 +0800 Message-Id: <1483790475-28250-1-git-send-email-cugyly@163.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-CM-TRANSID: EsCowACnwciX2HBYz+73HA--.31913S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3XrW3KFy8ArW8Jw4xJF4xWFg_yoWxuF4DpF 4jkwnrJrWxKFy2qrn3trs5CryYqFn7Xay7XrZ3GryFyrySqws3Jr1jy3s3tFWUAFZ7Cr47 u3WkWFW5urn8JFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07b0o7NUUUUU= X-Originating-IP: [220.179.147.21] X-CM-SenderInfo: pfxj5zr16rljoofrz/1tbiqxhY41UMCmNcNgAAsS Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: yuan linyu addtional move it to include/linux/timekeeping.h. reason to do this is poll_select_set_timeout() called by some functions which are not poll functions, and it's a pure time function, make it common. Signed-off-by: yuan linyu --- arch/alpha/kernel/osf_sys.c | 3 +-- fs/compat.c | 6 +++--- fs/select.c | 39 ++++++--------------------------------- include/linux/poll.h | 3 --- include/linux/timekeeping.h | 27 +++++++++++++++++++++++++++ net/socket.c | 2 +- 6 files changed, 38 insertions(+), 42 deletions(-) diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c index 54d8616..b7283a1 100644 --- a/arch/alpha/kernel/osf_sys.c +++ b/arch/alpha/kernel/osf_sys.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -1114,7 +1113,7 @@ SYSCALL_DEFINE5(osf_select, int, n, fd_set __user *, inp, fd_set __user *, outp, if (sec < 0 || usec < 0) return -EINVAL; - if (poll_select_set_timeout(to, sec, usec * NSEC_PER_USEC)) + if (set_normalized_timeout(to, sec, usec * NSEC_PER_USEC)) return -EINVAL; } diff --git a/fs/compat.c b/fs/compat.c index e50a211..9133468 100644 --- a/fs/compat.c +++ b/fs/compat.c @@ -1229,7 +1229,7 @@ COMPAT_SYSCALL_DEFINE5(select, int, n, compat_ulong_t __user *, inp, return -EFAULT; to = &end_time; - if (poll_select_set_timeout(to, + if (set_normalized_timeout(to, tv.tv_sec + (tv.tv_usec / USEC_PER_SEC), (tv.tv_usec % USEC_PER_SEC) * NSEC_PER_USEC)) return -EINVAL; @@ -1275,7 +1275,7 @@ static long do_compat_pselect(int n, compat_ulong_t __user *inp, return -EFAULT; to = &end_time; - if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec)) + if (set_normalized_timeout(to, ts.tv_sec, ts.tv_nsec)) return -EINVAL; } @@ -1344,7 +1344,7 @@ COMPAT_SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, return -EFAULT; to = &end_time; - if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec)) + if (set_normalized_timeout(to, ts.tv_sec, ts.tv_nsec)) return -EINVAL; } diff --git a/fs/select.c b/fs/select.c index 305c0da..f935422 100644 --- a/fs/select.c +++ b/fs/select.c @@ -259,34 +259,6 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int state, } EXPORT_SYMBOL(poll_schedule_timeout); -/** - * poll_select_set_timeout - helper function to setup the timeout value - * @to: pointer to timespec64 variable for the final timeout - * @sec: seconds (from user space) - * @nsec: nanoseconds (from user space) - * - * Note, we do not use a timespec for the user space value here, That - * way we can use the function for timeval and compat interfaces as well. - * - * Returns -EINVAL if sec/nsec are not normalized. Otherwise 0. - */ -int poll_select_set_timeout(struct timespec64 *to, time64_t sec, long nsec) -{ - struct timespec64 ts = {.tv_sec = sec, .tv_nsec = nsec}; - - if (!timespec64_valid(&ts)) - return -EINVAL; - - /* Optimize for the zero timeout value here */ - if (!sec && !nsec) { - to->tv_sec = to->tv_nsec = 0; - } else { - ktime_get_ts64(to); - *to = timespec64_add_safe(*to, ts); - } - return 0; -} - static int poll_select_copy_remaining(struct timespec64 *end_time, void __user *p, int timeval, int ret) @@ -643,7 +615,7 @@ SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp, return -EFAULT; to = &end_time; - if (poll_select_set_timeout(to, + if (set_normalized_timeout(to, tv.tv_sec + (tv.tv_usec / USEC_PER_SEC), (tv.tv_usec % USEC_PER_SEC) * NSEC_PER_USEC)) return -EINVAL; @@ -670,7 +642,7 @@ static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp, ts64 = timespec_to_timespec64(ts); to = &end_time; - if (poll_select_set_timeout(to, ts64.tv_sec, ts64.tv_nsec)) + if (set_normalized_timeout(to, ts64.tv_sec, ts64.tv_nsec)) return -EINVAL; } @@ -976,8 +948,9 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds, if (timeout_msecs >= 0) { to = &end_time; - poll_select_set_timeout(to, timeout_msecs / MSEC_PER_SEC, - NSEC_PER_MSEC * (timeout_msecs % MSEC_PER_SEC)); + if (set_normalized_timeout(to, timeout_msecs / MSEC_PER_SEC, + NSEC_PER_MSEC * (timeout_msecs % MSEC_PER_SEC))) + return -EINVAL; } ret = do_sys_poll(ufds, nfds, to); @@ -1016,7 +989,7 @@ SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds, return -EFAULT; to = &end_time; - if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec)) + if (set_normalized_timeout(to, ts.tv_sec, ts.tv_nsec)) return -EINVAL; } diff --git a/include/linux/poll.h b/include/linux/poll.h index a46d675..bfb5219 100644 --- a/include/linux/poll.h +++ b/include/linux/poll.h @@ -159,7 +159,4 @@ extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds, extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timespec64 *end_time); -extern int poll_select_set_timeout(struct timespec64 *to, time64_t sec, - long nsec); - #endif /* _LINUX_POLL_H */ diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index d2e804e..7aa877f 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -352,5 +352,32 @@ extern void read_boot_clock64(struct timespec64 *ts); extern int update_persistent_clock(struct timespec now); extern int update_persistent_clock64(struct timespec64 now); +/** + * set_normalized_timeout - helper function to setup the timeout value + * @to: pointer to timespec64 variable for the final timeout + * @sec: seconds (from user space) + * @nsec: nanoseconds (from user space) + * + * Note, we do not use a timespec for the user space value here, That + * way we can use the function for timeval and compat interfaces as well. + * + * Returns -EINVAL if sec/nsec are not normalized. Otherwise 0. + */ +static inline int set_normalized_timeout(struct timespec64 *to, time64_t sec, long nsec) +{ + struct timespec64 ts = {.tv_sec = sec, .tv_nsec = nsec}; + + if (!timespec64_valid(&ts)) + return -EINVAL; + + /* Optimize for the zero timeout value here */ + if (!sec && !nsec) { + to->tv_sec = to->tv_nsec = 0; + } else { + ktime_get_ts64(to); + *to = timespec64_add_safe(*to, ts); + } + return 0; +} #endif diff --git a/net/socket.c b/net/socket.c index a8c2307..2a296a8 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2217,7 +2217,7 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, struct timespec64 timeout64; if (timeout && - poll_select_set_timeout(&end_time, timeout->tv_sec, + set_normalized_timeout(&end_time, timeout->tv_sec, timeout->tv_nsec)) return -EINVAL;