[PATCH] fs: rename poll_select_set_timeout() to set_normalized_timeout()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: yuan linyu <Linyu.Yuan@xxxxxxxxxxxxxxxxxxxx>

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 <Linyu.Yuan@xxxxxxxxxxxxxxxxxxxx>
---
 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 <linux/stat.h>
 #include <linux/mman.h>
 #include <linux/shm.h>
-#include <linux/poll.h>
 #include <linux/file.h>
 #include <linux/types.h>
 #include <linux/ipc.h>
@@ -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;
 
-- 
2.7.4


--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux