diff options
-rw-r--r-- | sys/kern/tty.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c index f916a1b..bc95f04 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -97,6 +97,7 @@ __FBSDID("$FreeBSD$"); #include <sys/poll.h> #include <sys/kernel.h> #include <sys/vnode.h> +#include <sys/limits.h> #include <sys/serial.h> #include <sys/signalvar.h> #include <sys/resourcevar.h> @@ -1854,14 +1855,13 @@ loop: #undef diff /* * Rounding down may make us wake up just short - * of the target, so we round up. - * The formula is ceiling(slp * hz/1000000). - * 32-bit arithmetic is enough for hz < 169. - * XXX see tvtohz() for how to avoid overflow if hz - * is large (divide by `tick' and/or arrange to - * use tvtohz() if hz is large). + * of the target, so we round up. The 32 bit arithmetic is + * sufficient for the first calculation for hz < 169. */ - slp = (long) (((u_long)slp * hz) + 999999) / 1000000; + if (sizeof(u_long) > 4 || slp <= ULONG_MAX / hz) + slp = (long) (((u_long)slp * hz) + 999999) / 1000000; + else + slp = (slp + (tick - 1)) / tick; goto sleep; } if (qp->c_cc <= 0) { |