lkml.org 
[lkml]   [2009]   [Feb]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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


\
 
 \ /
  Last update: 2009-02-04 23:21    [W:0.072 / U:0.292 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site