Re: Serious bug in recent Linux kernels

Dan Kegel (dank@alumni.caltech.edu)
Tue, 12 Jan 1999 08:25:22 -0800


Matthew Hannigan <mha73@qantas.com.au> wrote:
> Dan Kegel <dank@alumni.caltech.edu> writes
> > timeout*HZ can overflow and produce a bad positive result for
> > some values of timeout, I think. Assuming timeout is
> > a long (I don't have the source handy), how about
> > if ((timeout < 0) || (timeout > LONG_MAX/HZ))
> > timeout =3D MAX_SCHEDULE_TIMEOUT;
> > else if (timeout > 0)
> > timeout =3D (timeout*HZ+999)/1000+1;
>
> Wouldn't it be wise to be explicit the assumptions on
> the range of HZ by preceding things like this with
> assertions?

Not really - if we code it correctly, it'll handle any
value of HZ from 1 to 2^20... you might need #ifdefs
to avoid constant math problems. e.g. in
/* Convert timeout from milliseconds into jiffies? */
if (((unsigned long)timeout) >= (1000*MAX_SCHEDULE_TIMEOUT)/HZ))
timeout = MAX_SCHEDULE_TIMEOUT;
else if (timeout > 0)
timeout = (timeout*HZ+999)/1000+1;
cpp might have a problem evaluating (1000*MAX_SCHEDULE_TIMEOUT)/HZ.

- Dan

-- 
Speaking only for myself, not for my employer

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/