Module Name: src
Committed By: riastradh
Date: Wed Jul 24 03:28:09 UTC 2013
Modified Files:
src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: kernel.h
Log Message:
Fix up some bit-hacking and pointer-futzing in <linux/kernel.h>.
- Avoid C arithmetic pitfalls and multiple evaluatoin in round_up.
- Add round_down.
- Explain why upper_32_bits and lower_32_bits exist.
- Explain what container_of does.
To generate a diff of this commit:
cvs rdiff -u -r1.1.2.17 -r1.1.2.18 \
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.17 src/sys/external/bsd/drm2/include/linux/kernel.h:1.1.2.18
--- src/sys/external/bsd/drm2/include/linux/kernel.h:1.1.2.17 Wed Jul 24 03:03:37 2013
+++ src/sys/external/bsd/drm2/include/linux/kernel.h Wed Jul 24 03:28:09 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: kernel.h,v 1.1.2.17 2013/07/24 03:03:37 riastradh Exp $ */
+/* $NetBSD: kernel.h,v 1.1.2.18 2013/07/24 03:28:09 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -46,11 +46,26 @@
#define uninitialized_var(x) x
-#define round_up(X, Y) roundup2(X, Y)
+/*
+ * Rounding to powers of two -- carefully avoiding multiple evaluation
+ * of arguments and pitfalls with C integer arithmetic rules.
+ */
+#define round_up(X, N) ((((X) - 1) | ((N) - 1)) + 1)
+#define round_down(X, N) ((X) & ~(uintmax_t)((N) - 1))
+/*
+ * These select 32-bit halves of what may be 32- or 64-bit quantities,
+ * for which straight 32-bit shifts may be undefined behaviour (and do
+ * the wrong thing on most machines: return the input unshifted by
+ * ignoring the upper bits of the shift count).
+ */
#define upper_32_bits(X) ((uint32_t) (((X) >> 16) >> 16))
#define lower_32_bits(X) ((uint32_t) ((X) & 0xffffffffUL))
+/*
+ * Given x = &c->f, container_of(x, T, f) gives us back c, where T is
+ * the type of c.
+ */
#define container_of(PTR, TYPE, FIELD) \
((void)sizeof((PTR) - \
&((TYPE *)(((char *)(PTR)) - \