Module Name: src
Committed By: riastradh
Date: Wed Jul 24 02:49:52 UTC 2013
Modified Files:
src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: kernel.h
Log Message:
Make container_of type-safe with the help of a judicious sizeof.
Still avoids multiple evaluation of the pointer operand expression.
To generate a diff of this commit:
cvs rdiff -u -r1.1.2.10 -r1.1.2.11 \
src/sys/external/bsd/drm2/include/linux/kernel.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/external/bsd/drm2/include/linux/kernel.h
diff -u src/sys/external/bsd/drm2/include/linux/kernel.h:1.1.2.10 src/sys/external/bsd/drm2/include/linux/kernel.h:1.1.2.11
--- src/sys/external/bsd/drm2/include/linux/kernel.h:1.1.2.10 Wed Jul 24 02:28:07 2013
+++ src/sys/external/bsd/drm2/include/linux/kernel.h Wed Jul 24 02:49:52 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: kernel.h,v 1.1.2.10 2013/07/24 02:28:07 riastradh Exp $ */
+/* $NetBSD: kernel.h,v 1.1.2.11 2013/07/24 02:49:52 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -41,7 +41,10 @@
#define unlikely(X) __predict_false(X)
#define container_of(PTR, TYPE, FIELD) \
- ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)))
+ ((void)sizeof((PTR) - \
+ &((TYPE *)(((char *)(PTR)) - \
+ offsetof(TYPE, FIELD)))->FIELD), \
+ ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD))))
#define ARRAY_SIZE(ARRAY) __arraycount(ARRAY)