Re: sparse warning, or why does jifies_to_msecs() return an int?

From: David Mosberger
Date: Sat Jan 15 2005 - 00:58:57 EST


>>>>> On Fri, 14 Jan 2005 20:29:07 -0800 (PST), Linus Torvalds <torvalds@xxxxxxxx> said:

>> 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?

Linus> There's no good way to shut up sparse, I think. The fact is,
Linus> we _are_ losing bits, but it doesn't matter much in this
Linus> case.

Yes, you're right.

Linus> I think "jiffies_to_msecs(MAX_JIFFY_OFFSET)" is fundamentally
Linus> a suspect operation (since the ranges are different for the
Linus> two types), and I think that the sparse warnign is correct,
Linus> but it's one of those "doing the wrong thing is not always
Linus> wrogn enough to matter".

How about something along the lines of the attached? The test in
msecs_to_jiffies is non-sensical for HZ>=1000 because

(a) jiffies_to_msecs(x) <= x, if HZ >= 1000, and
(b) MAX_UINT <= MAX_ULONG

--david

===== include/linux/jiffies.h 1.11 vs edited =====
--- 1.11/include/linux/jiffies.h 2005-01-04 18:48:02 -08:00
+++ edited/include/linux/jiffies.h 2005-01-14 21:52:46 -08:00
@@ -276,8 +276,10 @@

static inline unsigned long msecs_to_jiffies(const unsigned int m)
{
+#if HZ < 1000
if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
return MAX_JIFFY_OFFSET;
+#endif
#if HZ <= 1000 && !(1000 % HZ)
return (m + (1000 / HZ) - 1) / (1000 / HZ);
#elif HZ > 1000 && !(HZ % 1000)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/