@@ -428,7 +428,7 @@ static void wq_add(struct mqueue_inode_info *info, int sr,
428428 * sr: SEND or RECV
429429 */
430430static int wq_sleep (struct mqueue_inode_info * info , int sr ,
431- long timeout , struct ext_wait_queue * ewp )
431+ ktime_t * timeout , struct ext_wait_queue * ewp )
432432{
433433 int retval ;
434434 signed long time ;
@@ -439,7 +439,8 @@ static int wq_sleep(struct mqueue_inode_info *info, int sr,
439439 set_current_state (TASK_INTERRUPTIBLE );
440440
441441 spin_unlock (& info -> lock );
442- time = schedule_timeout (timeout );
442+ time = schedule_hrtimeout_range_clock (timeout ,
443+ HRTIMER_MODE_ABS , 0 , CLOCK_REALTIME );
443444
444445 while (ewp -> state == STATE_PENDING )
445446 cpu_relax ();
@@ -551,31 +552,16 @@ static void __do_notify(struct mqueue_inode_info *info)
551552 wake_up (& info -> wait_q );
552553}
553554
554- static long prepare_timeout (struct timespec * p )
555+ static int prepare_timeout (const struct timespec __user * u_abs_timeout ,
556+ ktime_t * expires , struct timespec * ts )
555557{
556- struct timespec nowts ;
557- long timeout ;
558-
559- if (p ) {
560- if (unlikely (p -> tv_nsec < 0 || p -> tv_sec < 0
561- || p -> tv_nsec >= NSEC_PER_SEC ))
562- return - EINVAL ;
563- nowts = CURRENT_TIME ;
564- /* first subtract as jiffies can't be too big */
565- p -> tv_sec -= nowts .tv_sec ;
566- if (p -> tv_nsec < nowts .tv_nsec ) {
567- p -> tv_nsec += NSEC_PER_SEC ;
568- p -> tv_sec -- ;
569- }
570- p -> tv_nsec -= nowts .tv_nsec ;
571- if (p -> tv_sec < 0 )
572- return 0 ;
573-
574- timeout = timespec_to_jiffies (p ) + 1 ;
575- } else
576- return MAX_SCHEDULE_TIMEOUT ;
558+ if (copy_from_user (ts , u_abs_timeout , sizeof (struct timespec )))
559+ return - EFAULT ;
560+ if (!timespec_valid (ts ))
561+ return - EINVAL ;
577562
578- return timeout ;
563+ * expires = timespec_to_ktime (* ts );
564+ return 0 ;
579565}
580566
581567static void remove_notification (struct mqueue_inode_info * info )
@@ -861,22 +847,21 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
861847 struct ext_wait_queue * receiver ;
862848 struct msg_msg * msg_ptr ;
863849 struct mqueue_inode_info * info ;
864- struct timespec ts , * p = NULL ;
865- long timeout ;
850+ ktime_t expires , * timeout = NULL ;
851+ struct timespec ts ;
866852 int ret ;
867853
868854 if (u_abs_timeout ) {
869- if ( copy_from_user ( & ts , u_abs_timeout ,
870- sizeof ( struct timespec )) )
871- return - EFAULT ;
872- p = & ts ;
855+ int res = prepare_timeout ( u_abs_timeout , & expires , & ts );
856+ if ( res )
857+ return res ;
858+ timeout = & expires ;
873859 }
874860
875861 if (unlikely (msg_prio >= (unsigned long ) MQ_PRIO_MAX ))
876862 return - EINVAL ;
877863
878- audit_mq_sendrecv (mqdes , msg_len , msg_prio , p );
879- timeout = prepare_timeout (p );
864+ audit_mq_sendrecv (mqdes , msg_len , msg_prio , timeout ? & ts : NULL );
880865
881866 filp = fget (mqdes );
882867 if (unlikely (!filp )) {
@@ -918,9 +903,6 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
918903 if (filp -> f_flags & O_NONBLOCK ) {
919904 spin_unlock (& info -> lock );
920905 ret = - EAGAIN ;
921- } else if (unlikely (timeout < 0 )) {
922- spin_unlock (& info -> lock );
923- ret = timeout ;
924906 } else {
925907 wait .task = current ;
926908 wait .msg = (void * ) msg_ptr ;
@@ -953,24 +935,23 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
953935 size_t , msg_len , unsigned int __user * , u_msg_prio ,
954936 const struct timespec __user * , u_abs_timeout )
955937{
956- long timeout ;
957938 ssize_t ret ;
958939 struct msg_msg * msg_ptr ;
959940 struct file * filp ;
960941 struct inode * inode ;
961942 struct mqueue_inode_info * info ;
962943 struct ext_wait_queue wait ;
963- struct timespec ts , * p = NULL ;
944+ ktime_t expires , * timeout = NULL ;
945+ struct timespec ts ;
964946
965947 if (u_abs_timeout ) {
966- if ( copy_from_user ( & ts , u_abs_timeout ,
967- sizeof ( struct timespec )) )
968- return - EFAULT ;
969- p = & ts ;
948+ int res = prepare_timeout ( u_abs_timeout , & expires , & ts );
949+ if ( res )
950+ return res ;
951+ timeout = & expires ;
970952 }
971953
972- audit_mq_sendrecv (mqdes , msg_len , 0 , p );
973- timeout = prepare_timeout (p );
954+ audit_mq_sendrecv (mqdes , msg_len , 0 , timeout ? & ts : NULL );
974955
975956 filp = fget (mqdes );
976957 if (unlikely (!filp )) {
@@ -1002,11 +983,6 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
1002983 if (filp -> f_flags & O_NONBLOCK ) {
1003984 spin_unlock (& info -> lock );
1004985 ret = - EAGAIN ;
1005- msg_ptr = NULL ;
1006- } else if (unlikely (timeout < 0 )) {
1007- spin_unlock (& info -> lock );
1008- ret = timeout ;
1009- msg_ptr = NULL ;
1010986 } else {
1011987 wait .task = current ;
1012988 wait .state = STATE_NONE ;
0 commit comments