Re: [git pull] timer fix

From: Linus Torvalds
Date: Wed Feb 04 2009 - 17:17:31 EST




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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/