[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: testing/pre-7 and do_poll()
On Sun, 10 Jan 1999, Chip Salzenberg wrote:
>
> Got it, like it -- *except* the fix for overflow in do_poll() is a
> little bit off. Quoting testing/pre-7:
>
> if (timeout) {
> /* Carefula about overflow in the intermediate values */
> if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
> timeout = (timeout*HZ+999)/1000+1;
> else /* Negative or overflow */
> timeout = MAX_SCHEDULE_TIMEOUT;
> }
>
> However, the maximum legal millisecond timeout isn't (as shown)
> MAX_SCHEDULE_TIMEOUT/HZ, but rather MAX_SCHEDULE_TIMEOUT/(1000/HZ).
> So this code will turn some large timeouts into MAX_SCHEDULE_TIMEOUT
> unnecessarily.
Note the comment (and do NOT look at the speeling).
In particular, we need to make sure the _intermediate_ value doesn'
toverflow. We could do that by using 64-bit arithmetic, but let's not.
> ! if (timeout < 0)
> ! timeout = MAX_SCHEDULE_TIMEOUT;
> ! else if (timeout)
> ! timeout = ROUND_UP(timeout, 1000/HZ);
Eh? And re-introduce the original bug?
Linus
--
This is a majordomo managed list. To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: majordomo@kvack.org