diff options
author | Alejandro Colomar <alx.manpages@gmail.com> | 2021-11-19 16:47:48 +0100 |
---|---|---|
committer | Alejandro Colomar <alx.manpages@gmail.com> | 2021-11-20 13:21:59 +0100 |
commit | c3b4f8fdf103d898ffd4c9022b71f5fc6ce617dc (patch) | |
tree | 8b7d630ca71d64e536cf72d767f3ec7ea0917207 | |
parent | 864373a244462af3b0cb32ce0a98df74b1965e87 (diff) |
linux/kernel.h, linux/array_size.h: Split ARRAY_SIZE() into a separate header
Include <linux/array_size.h> from <linux/kernel.h> for compatibility.
Include <linux/compiler.h> for __must_be_array().
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
-rw-r--r-- | include/linux/array_size.h | 15 | ||||
-rw-r--r-- | include/linux/kernel.h | 9 |
2 files changed, 18 insertions, 6 deletions
diff --git a/include/linux/array_size.h b/include/linux/array_size.h new file mode 100644 index 000000000000..cba90f2248ef --- /dev/null +++ b/include/linux/array_size.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_ARRAY_SIZE_H +#define _LINUX_ARRAY_SIZE_H + +#include <linux/compiler.h> + + +/** + * ARRAY_SIZE - get the number of elements in array @a + * @a: array to be sized + */ +#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]) + __must_be_array(a)) + + +#endif /* _LINUX_ARRAY_SIZE_H */ diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 77755ac3e189..db6021ce3e0e 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -2,6 +2,8 @@ #ifndef _LINUX_KERNEL_H #define _LINUX_KERNEL_H + +#include <linux/array_size.h> #include <linux/stdarg.h> #include <linux/align.h> #include <linux/limits.h> @@ -25,6 +27,7 @@ #include <uapi/linux/kernel.h> + #define STACK_MAGIC 0xdeadbeef /** @@ -39,12 +42,6 @@ #define READ 0 #define WRITE 1 -/** - * ARRAY_SIZE - get the number of elements in array @arr - * @arr: array to be sized - */ -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) - #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) #define u64_to_user_ptr(x) ( \ |