[rft, PATCH v1 4/4] kernel.h: Split out ARRAY_SZIE()

From: Andy Shevchenko
Date: Mon Oct 24 2022 - 11:22:16 EST


kernel.h is being used as a dump for all kinds of stuff for a long time.
ARRAY_SIZE() is used in many drivers without need of the full kernel.h
dependency train with it.

Here is the attempt on cleaning it up by splitting out ARRAY_SIZE().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
include/linux/array_size.h | 13 +++++++++++++
include/linux/kernel.h | 8 +-------
2 files changed, 14 insertions(+), 7 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..c9cdba26555f
--- /dev/null
+++ b/include/linux/array_size.h
@@ -0,0 +1,13 @@
+/* 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 @arr
+ * @arr: array to be sized
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+
+#endif /* _LINUX_ARRAY_SIZE_H */
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 7e9612de01b8..011eab2b0e93 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -17,7 +17,7 @@
#include <linux/linkage.h>
#include <linux/stddef.h>
#include <linux/types.h>
-#include <linux/compiler.h>
+#include <linux/array_size.h>
#include <linux/container_of.h>
#include <linux/bitops.h>
#include <linux/hex.h>
@@ -46,12 +46,6 @@
*/
#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))

-/**
- * 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.35.1