Messages in this thread | | | Date | Wed, 4 Feb 2009 14:16:23 -0800 (PST) | From | Linus Torvalds <> | Subject | Re: [git pull] timer fix |
| |
On Wed, 4 Feb 2009, Linus Torvalds wrote: > > Either cast the result of the subtract to "s32" (or "int", whatever), or > cast _both_ of them to (s32) so that the subtract is done in a signed > type, and then the expansion to (long) will still be right - but > unnecessary - in the sign.
Btw, doing it with a nice helper macro or function is also perhaps a good idea, at least if these "compare hpet values" things happen more than once.
Look at "time_after()" in <linux/jiffies.h> to see how to do these kinds of "comparisons of things that may overflow" really carefully. You absolutely need to do the compare in a size that is no larger than the size of the actual values (and in the case of HPET, it's 32-bit, at least the way we do things now - I guess HPET's _could_ be 64-bit, but we don't read more than 32 bits or whatever).
So <linux/jiffies.h> does the cast to "(long)", but it does so because the incoming values really have type "unsigned long" and are valid in all bits.
Linus
| |