PROBLEM: compiler warning from cryptic pointer math

From: Chris Metcalf
Date: Fri Jun 23 2006 - 15:42:16 EST


(Using the format from REPORTING-BUGS...)

[1.] compiler warning from cryptic pointer math

[2.] This change simplifies a cryptic macro in fs/readdir.c. Rather
than subtracting an uninitialized pointer's d_name field address from
the uninitialized pointer base to get the field offset, we just use the
normal "offsetof" idiom to directly get the d_name field address from a
pointer to zero. We can't use offsetof directly since the variable type
we have handy is a pointer, not the structure type itself.

(Our compiler is a gcc-alike that can figure out that it doesn't need to warn about things like "foo - foo" for an uninitialized pointer foo, but the field reference makes it think the pointer is truly being used; the warning made me look more closely at this piece of code.)

[4.] The kernel version is 2.6.17.1.

[X.]

--- /tmp/tmp.3955.0 2006-06-23 10:10:54.000000000 -0400
+++ /u/cmetcalf/linux/fs/readdir.c 2006-06-23 10:09:07.000000000 -0400
@@ -51,7 +51,7 @@
* anyway. Thus the special "fillonedir()" function for that
* case (the low-level handlers don't need to care about this).
*/
-#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
+#define NAME_OFFSET(de) ((int) ((typeof(de))0)->d_name)
#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))

#ifdef __ARCH_WANT_OLD_READDIR

--
Chris Metcalf, Tilera Corp.
http://www.tilera.com


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