linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Wrong use of MAX_JIFFY_OFFSET?
@ 2012-03-28  7:12 Liu Yu
  2012-04-06 19:05 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Yu @ 2012-03-28  7:12 UTC (permalink / raw)
  To: linux-kernel

Hi guys,

I saw a couple of places in current kernel have this kind of code:

> static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
> {
>         unsigned long end = jiffies;
>
>         if (end >= start)
>                return jiffies_to_msecs(end - start);
>
>         return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
> }

As you know, jiffies has a type of unsigned long, so if we know which is the
end and
which is the start, then (end - start) can simply figure out how much
jiffies flies,
without worry about the overflow.

Look at the code above, assume that there is just an overflow happening on
jiffies: end=0 and start=~0UL.
Since end < start, then the return value of the function is
jiffies_to_msecs(MAX_JIFFY_OFFSET+2).
But shouldn't the correct value be jiffies_to_msecs(1)?

could someone tell me that am I missing anything?

Thanks,
Yu


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-09  2:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-28  7:12 Wrong use of MAX_JIFFY_OFFSET? Liu Yu
2012-04-06 19:05 ` Andrew Morton
2012-04-09  2:18   ` Liu Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).