aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/time.c')
-rw-r--r--kernel/time.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/kernel/time.c b/kernel/time.c
index 343e2515375a..cbe0d5a222ff 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -392,13 +392,17 @@ EXPORT_SYMBOL(set_normalized_timespec);
392struct timespec ns_to_timespec(const s64 nsec) 392struct timespec ns_to_timespec(const s64 nsec)
393{ 393{
394 struct timespec ts; 394 struct timespec ts;
395 s32 rem;
395 396
396 if (!nsec) 397 if (!nsec)
397 return (struct timespec) {0, 0}; 398 return (struct timespec) {0, 0};
398 399
399 ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, &ts.tv_nsec); 400 ts.tv_sec = div_s64_rem(nsec, NSEC_PER_SEC, &rem);
400 if (unlikely(nsec < 0)) 401 if (unlikely(rem < 0)) {
401 set_normalized_timespec(&ts, ts.tv_sec, ts.tv_nsec); 402 ts.tv_sec--;
403 rem += NSEC_PER_SEC;
404 }
405 ts.tv_nsec = rem;
402 406
403 return ts; 407 return ts;
404} 408}
@@ -528,8 +532,10 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
528 * Convert jiffies to nanoseconds and separate with 532 * Convert jiffies to nanoseconds and separate with
529 * one divide. 533 * one divide.
530 */ 534 */
531 u64 nsec = (u64)jiffies * TICK_NSEC; 535 u32 rem;
532 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &value->tv_nsec); 536 value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,
537 NSEC_PER_SEC, &rem);
538 value->tv_nsec = rem;
533} 539}
534EXPORT_SYMBOL(jiffies_to_timespec); 540EXPORT_SYMBOL(jiffies_to_timespec);
535 541
@@ -567,12 +573,11 @@ void jiffies_to_timeval(const unsigned long jiffies, struct timeval *value)
567 * Convert jiffies to nanoseconds and separate with 573 * Convert jiffies to nanoseconds and separate with
568 * one divide. 574 * one divide.
569 */ 575 */
570 u64 nsec = (u64)jiffies * TICK_NSEC; 576 u32 rem;
571 long tv_usec;
572 577
573 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tv_usec); 578 value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,
574 tv_usec /= NSEC_PER_USEC; 579 NSEC_PER_SEC, &rem);
575 value->tv_usec = tv_usec; 580 value->tv_usec = rem / NSEC_PER_USEC;
576} 581}
577EXPORT_SYMBOL(jiffies_to_timeval); 582EXPORT_SYMBOL(jiffies_to_timeval);
578 583