aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/linux/stddef.h
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2018-01-10 12:53:20 -0800
committerKees Cook <keescook@chromium.org>2018-01-15 12:07:46 -0800
commit4229a470175be14e1d2648713be8a5e8e8fbea02 (patch)
tree9800d572b0046b2226f1b853f15c3055e304078e /include/linux/stddef.h
parentlkdtm/usercopy: Adjust test to include an offset to check reporting (diff)
downloadwireguard-linux-4229a470175be14e1d2648713be8a5e8e8fbea02.tar.xz
wireguard-linux-4229a470175be14e1d2648713be8a5e8e8fbea02.zip
stddef.h: Introduce sizeof_field()
The size of fields within a structure is needed in a few places in the kernel already, and will be needed for the usercopy whitelisting when declaring whitelist regions within structures. This creates a dedicated macro and redefines offsetofend() to use it. Existing usage, ignoring the 1200+ lustre assert uses: $ git grep -E 'sizeof\(\(\((struct )?[a-zA-Z_]+ \*\)0\)->' | \ grep -v staging/lustre | wc -l 65 Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'include/linux/stddef.h')
-rw-r--r--include/linux/stddef.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index 2181719fd907..998a4ba28eba 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -20,12 +20,20 @@ enum {
#endif
/**
+ * sizeof_field(TYPE, MEMBER)
+ *
+ * @TYPE: The structure containing the field of interest
+ * @MEMBER: The field to return the size of
+ */
+#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+
+/**
* offsetofend(TYPE, MEMBER)
*
* @TYPE: The type of the structure
* @MEMBER: The member within the structure to get the end offset of
*/
#define offsetofend(TYPE, MEMBER) \
- (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))
+ (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
#endif