kernel/time.c: integer constant is too large for long type

From: Carlos R. Mafra
Date: Thu May 01 2008 - 22:48:22 EST


Hi Peter,

I would like to report a gcc warning which caught my attention today:

kernel/time.c: In function msecs_to_jiffies:
kernel/time.c:479: warning: integer constant is too large for long type
kernel/time.c: In function usecs_to_jiffies:
kernel/time.c:494: warning: integer constant is too large for long type

and ask you if this is something I should worry about (and propose
a patch if this warning is harmless).

I ask this because this warning was introduced via commit
bdc807871d58285737d50dc6163d0feb72cb0dc2 ("avoid overflows in kernel/time.c")
and (naively) for me it looks like the above gcc warning is some kind of
overflow.

I looked in the code for the first warning:

return ((u64)MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
>> MSEC_TO_HZ_SHR32;

and noticed that the warning is due to

#define MSEC_TO_HZ_ADJ32 0x1cccccccc

in kernel/timeconst.h

Just for fun I converted it to binary
111001100110011001100110011001100
and noticed that there are 33 bits in it.

I also noticed that if I cast it to (u64)MSEC_TO_HZ_ADJ32 the warning
is gone, but it appears to be an ugly thing to do. I can understand
the first cast to u64 in the return written above because of the
multiplication by 'm'. But it looks strange to do that to MSEC_TO_HZ_ADJ32
alone.

Shouldn't MSEC_TO_HZ_ADJ32 have at most 32 bits?

Well, just in case there is no problem about it being 33 bits despite
its name, please consider the patch below, which silences these
warnings.