public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* sparse warning, or why does jifies_to_msecs() return an int?
@ 2005-01-15  2:21 David Mosberger
  2005-01-15  4:29 ` Linus Torvalds
  2005-05-03 18:43 ` Nish Aravamudan
  0 siblings, 2 replies; 6+ messages in thread
From: David Mosberger @ 2005-01-15  2:21 UTC (permalink / raw)
  To: schwidefsky, torvalds; +Cc: linux-kernel

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

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

end of thread, other threads:[~2005-05-03 18:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-15  2:21 sparse warning, or why does jifies_to_msecs() return an int? David Mosberger
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox