Messages in this thread Patch in this message | | | From | Alejandro Colomar <> | Subject | [PATCH v2 06/20] linux/kernel.h, linux/array_size.h: Split ARRAY_SIZE() into a separate header | Date | Sat, 20 Nov 2021 14:00:49 +0100 |
| |
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> --- include/linux/array_size.h | 15 +++++++++++++++ include/linux/kernel.h | 9 +++------ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 include/linux/array_size.h
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) ( \ -- 2.33.1
| |