From: David Mosberger <davidm@napali.hpl.hp.com>
To: schwidefsky@de.ibm.com, torvalds@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: sparse warning, or why does jifies_to_msecs() return an int?
Date: Fri, 14 Jan 2005 18:21:02 -0800 [thread overview]
Message-ID: <200501150221.j0F2L2aD021862@napali.hpl.hp.com> (raw)
I'm seeing the following warning from sparse:
include/linux/jiffies.h:262:9: warning: cast truncates bits from constant value (3ffffffffffffffe becomes fffffffe)
it took me a while to realize that this is due to
the jiffies_to_msecs(MAX_JIFFY_OFFSET) call in
msecs_to_jiffies() and due to the fact that
jiffies_to_msecs() returns only an "unsigned int".
Is there are a good reason to constrain the return value to 4 billion
msecs? If so, what's the proper way to shut up sparse?
On a related note, there seem to be some overflow issues in
jiffies_to_{msec,usec}. For example:
return (j * 1000) / HZ;
can overflow if j > MAXULONG/1000, which is the case for
MAX_JIFFY_OFFSET.
I think it would be better to use:
return 1000*(j/HZ) + 1000*(j%HZ)/HZ;
instead. No?
--david
next reply other threads:[~2005-01-15 2:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-15 2:21 David Mosberger [this message]
2005-01-15 4:29 ` Linus Torvalds
2005-01-15 5:57 ` David Mosberger
2005-01-15 18:05 ` Linus Torvalds
2005-01-20 23:46 ` David Mosberger
2005-05-03 18:43 ` Nish Aravamudan
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=200501150221.j0F2L2aD021862@napali.hpl.hp.com \
--to=davidm@napali.hpl.hp.com \
--cc=davidm@hpl.hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=schwidefsky@de.ibm.com \
--cc=torvalds@osdl.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®