Re: linux-next: Tree for October 2: percpu compile warnings (i386)

From: Randy Dunlap
Date: Fri Oct 02 2009 - 12:41:47 EST


mm/percpu.c:1873: warning: comparison of distinct pointer types lacks a cast
mm/percpu.c:1879: warning: format '%lx' expects type 'long unsigned int', but argument 2 has type 'size_t'

The second one is easily fixed (s/%lx/%zu/), but is that the correct fix?

The first one is a max(size_t, unsigned long).
The C99 spec says that the max value of a size_t is:
limit of size_t
SIZE_MAX 65535
(from 7.8.13(2)), but max_distance (the size_t here) is being compared to
unsigned long base_offset, which isn't limited to 65535 AFAICT.

In fact, this test:
if (max_distance > (VMALLOC_END - VMALLOC_START) * 3 / 4) {
checks max_distance > 0x000017ff_ffffffff (on x86_64).

And it looks to me like there is some potential for some value truncation
in the max() operation, even if size_t is not limited to SIZE_MAX.

So maybe the size_t(s) should be changed to unsigned long and the
printk format doesn't need to be fixed... ?

---
~Randy
--
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/