From: "Liu Yu" <liuyums@bwstor.com.cn>
To: <linux-kernel@vger.kernel.org>
Subject: Wrong use of MAX_JIFFY_OFFSET?
Date: Wed, 28 Mar 2012 15:12:24 +0800 [thread overview]
Message-ID: <006001cd0cb2$20f547b0$62dfd710$@com.cn> (raw)
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
next reply other threads:[~2012-03-28 7:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-28 7:12 Liu Yu [this message]
2012-04-06 19:05 ` Wrong use of MAX_JIFFY_OFFSET? Andrew Morton
2012-04-09 2:18 ` Liu Yu
-- strict thread matches above, loose matches on Subject: below --
2012-03-27 1:25 Liu Yu
2012-03-27 8:54 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='006001cd0cb2$20f547b0$62dfd710$@com.cn' \
--to=liuyums@bwstor.com.cn \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.