@@ -819,31 +819,21 @@ int common_timer_set(struct k_itimer *timr, int flags,
819819 return 0 ;
820820}
821821
822- /* Set a POSIX.1b interval timer */
823- SYSCALL_DEFINE4 (timer_settime , timer_t , timer_id , int , flags ,
824- const struct itimerspec __user * , new_setting ,
825- struct itimerspec __user * , old_setting )
822+ static int do_timer_settime (timer_t timer_id , int flags ,
823+ struct itimerspec64 * new_spec64 ,
824+ struct itimerspec64 * old_spec64 )
826825{
827- struct itimerspec64 new_spec64 , old_spec64 ;
828- struct itimerspec64 * rtn = old_setting ? & old_spec64 : NULL ;
829- struct itimerspec new_spec , old_spec ;
826+ const struct k_clock * kc ;
830827 struct k_itimer * timr ;
831828 unsigned long flag ;
832- const struct k_clock * kc ;
833829 int error = 0 ;
834830
835- if (!new_setting )
831+ if (!timespec64_valid (& new_spec64 -> it_interval ) ||
832+ !timespec64_valid (& new_spec64 -> it_value ))
836833 return - EINVAL ;
837834
838- if (copy_from_user (& new_spec , new_setting , sizeof (new_spec )))
839- return - EFAULT ;
840- new_spec64 = itimerspec_to_itimerspec64 (& new_spec );
841-
842- if (!timespec64_valid (& new_spec64 .it_interval ) ||
843- !timespec64_valid (& new_spec64 .it_value ))
844- return - EINVAL ;
845- if (rtn )
846- memset (rtn , 0 , sizeof (* rtn ));
835+ if (old_spec64 )
836+ memset (old_spec64 , 0 , sizeof (* old_spec64 ));
847837retry :
848838 timr = lock_timer (timer_id , & flag );
849839 if (!timr )
@@ -853,22 +843,71 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
853843 if (WARN_ON_ONCE (!kc || !kc -> timer_set ))
854844 error = - EINVAL ;
855845 else
856- error = kc -> timer_set (timr , flags , & new_spec64 , rtn );
846+ error = kc -> timer_set (timr , flags , new_spec64 , old_spec64 );
857847
858848 unlock_timer (timr , flag );
859849 if (error == TIMER_RETRY ) {
860- rtn = NULL ; // We already got the old time...
850+ old_spec64 = NULL ; // We already got the old time...
861851 goto retry ;
862852 }
863853
864- old_spec = itimerspec64_to_itimerspec (& old_spec64 );
865- if (old_setting && !error &&
866- copy_to_user (old_setting , & old_spec , sizeof (old_spec )))
867- error = - EFAULT ;
854+ return error ;
855+ }
856+
857+ /* Set a POSIX.1b interval timer */
858+ SYSCALL_DEFINE4 (timer_settime , timer_t , timer_id , int , flags ,
859+ const struct itimerspec __user * , new_setting ,
860+ struct itimerspec __user * , old_setting )
861+ {
862+ struct itimerspec64 new_spec64 , old_spec64 ;
863+ struct itimerspec64 * rtn = old_setting ? & old_spec64 : NULL ;
864+ struct itimerspec new_spec ;
865+ int error = 0 ;
866+
867+ if (!new_setting )
868+ return - EINVAL ;
868869
870+ if (copy_from_user (& new_spec , new_setting , sizeof (new_spec )))
871+ return - EFAULT ;
872+ new_spec64 = itimerspec_to_itimerspec64 (& new_spec );
873+
874+ error = do_timer_settime (timer_id , flags , & new_spec64 , rtn );
875+ if (!error && old_setting ) {
876+ struct itimerspec old_spec ;
877+ old_spec = itimerspec64_to_itimerspec (& old_spec64 );
878+ if (copy_to_user (old_setting , & old_spec , sizeof (old_spec )))
879+ error = - EFAULT ;
880+ }
869881 return error ;
870882}
871883
884+ #ifdef CONFIG_COMPAT
885+ COMPAT_SYSCALL_DEFINE4 (timer_settime , timer_t , timer_id , int , flags ,
886+ struct compat_itimerspec __user * , new ,
887+ struct compat_itimerspec __user * , old )
888+ {
889+ struct itimerspec64 new_spec64 , old_spec64 ;
890+ struct itimerspec64 * rtn = old ? & old_spec64 : NULL ;
891+ struct itimerspec new_spec ;
892+ int error = 0 ;
893+
894+ if (!new )
895+ return - EINVAL ;
896+ if (get_compat_itimerspec (& new_spec , new ))
897+ return - EFAULT ;
898+
899+ new_spec64 = itimerspec_to_itimerspec64 (& new_spec );
900+ error = do_timer_settime (timer_id , flags , & new_spec64 , rtn );
901+ if (!error && old ) {
902+ struct itimerspec old_spec ;
903+ old_spec = itimerspec64_to_itimerspec (& old_spec64 );
904+ if (put_compat_itimerspec (old , & old_spec ))
905+ error = - EFAULT ;
906+ }
907+ return error ;
908+ }
909+ #endif
910+
872911int common_timer_del (struct k_itimer * timer )
873912{
874913 const struct k_clock * kc = timer -> kclock ;
0 commit comments