kernel.h: removed REPEAT_BYTE from kernel.h
authorTanzir Hasan <tanzirh@google.com>
Tue, 26 Dec 2023 18:00:00 +0000 (18:00 +0000)
committerKees Cook <keescook@chromium.org>
Thu, 1 Feb 2024 17:47:59 +0000 (09:47 -0800)
This patch creates wordpart.h and includes it in asm/word-at-a-time.h
for all architectures. WORD_AT_A_TIME_CONSTANTS depends on kernel.h
because of REPEAT_BYTE. Moving this to another header and including it
where necessary allows us to not include the bloated kernel.h. Making
this implicit dependency on REPEAT_BYTE explicit allows for later
improvements in the lib/string.c inclusion list.

Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Tanzir Hasan <tanzirh@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20231226-libstringheader-v6-1-80aa08c7652c@google.com
Signed-off-by: Kees Cook <keescook@chromium.org>
12 files changed:
arch/arm/include/asm/word-at-a-time.h
arch/arm64/include/asm/word-at-a-time.h
arch/powerpc/include/asm/word-at-a-time.h
arch/riscv/include/asm/word-at-a-time.h
arch/s390/include/asm/word-at-a-time.h
arch/sh/include/asm/word-at-a-time.h
arch/x86/include/asm/word-at-a-time.h
arch/x86/kvm/mmu/mmu.c
fs/namei.c
include/asm-generic/word-at-a-time.h
include/linux/kernel.h
include/linux/wordpart.h [new file with mode: 0644]

index 352ab213520d20948442ad229a93a310f6f0343a..f9a3897b06e7ff8af5ae5887ed0b0949b9b93c3b 100644 (file)
@@ -8,7 +8,8 @@
  * Little-endian word-at-a-time zero byte handling.
  * Heavily based on the x86 algorithm.
  */
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 
 struct word_at_a_time {
        const unsigned long one_bits, high_bits;
index f3b151ed0d7a07ca2a4d64d99c361b54dd327763..14251abee23c0100f41430a13b4edb945d1e0f3f 100644 (file)
@@ -9,7 +9,8 @@
 
 #ifndef __AARCH64EB__
 
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 
 struct word_at_a_time {
        const unsigned long one_bits, high_bits;
index 30a12d2086871304bde578156b71557fda67da51..54653a86341490fcd9e352ce6e361c353891310d 100644 (file)
@@ -4,8 +4,8 @@
 /*
  * Word-at-a-time interfaces for PowerPC.
  */
-
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 #include <asm/asm-compat.h>
 #include <asm/extable.h>
 
index f3f031e34191d6fb993f650126be4dc793fee3ed..3802cda71ab7eedca3caaceb2d4a56dbe7fbc838 100644 (file)
@@ -10,7 +10,8 @@
 
 
 #include <asm/asm-extable.h>
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 
 struct word_at_a_time {
        const unsigned long one_bits, high_bits;
index 2579f1694b82f4311a9e7faf721fad782426b4ff..203acd6e431b12651af06f3234a8587c7bc4dc20 100644 (file)
@@ -2,7 +2,8 @@
 #ifndef _ASM_WORD_AT_A_TIME_H
 #define _ASM_WORD_AT_A_TIME_H
 
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 #include <asm/asm-extable.h>
 #include <asm/bitsperlong.h>
 
index 4aa398455b94abf4d72bb3fd0d14fee68f55e6f7..95100ce128d616f02a1e2dc07a04ab61f7e1ed7a 100644 (file)
@@ -5,6 +5,8 @@
 #ifdef CONFIG_CPU_BIG_ENDIAN
 # include <asm-generic/word-at-a-time.h>
 #else
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 /*
  * Little-endian version cribbed from x86.
  */
index 46b4f1f7f3545285bcad688348941d3bf0c6589e..e8d7d4941c4cffed9a9735d65f2ec81aa6992687 100644 (file)
@@ -2,7 +2,8 @@
 #ifndef _ASM_WORD_AT_A_TIME_H
 #define _ASM_WORD_AT_A_TIME_H
 
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 
 /*
  * This is largely generic for little-endian machines, but the
index 2d6cdeab1f8a3e78306148d44a4665a1d51d8b1e..6bb42b4fddb4e6635b2b2f1b5598e6fd81976780 100644 (file)
@@ -47,6 +47,7 @@
 #include <linux/kern_levels.h>
 #include <linux/kstrtox.h>
 #include <linux/kthread.h>
+#include <linux/wordpart.h>
 
 #include <asm/page.h>
 #include <asm/memtype.h>
index 4e0de939fea127034c24d7badb18253a9351b52e..6a548c2c40b98d9f91b1c16f247c3034e0716c15 100644 (file)
@@ -17,8 +17,8 @@
 
 #include <linux/init.h>
 #include <linux/export.h>
-#include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/wordpart.h>
 #include <linux/fs.h>
 #include <linux/filelock.h>
 #include <linux/namei.h>
index 95a1d214108a5d38f01fb98108028f321e3c6d4e..ef3f841c6625cffde7915b9551c36a5ac5cb8342 100644 (file)
@@ -2,7 +2,8 @@
 #ifndef _ASM_WORD_AT_A_TIME_H
 #define _ASM_WORD_AT_A_TIME_H
 
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
 #include <asm/byteorder.h>
 
 #ifdef __BIG_ENDIAN
index d9ad21058eed9d8820bc945f8d2f9715ae673b76..f4a1d582b79d24163e72a57541149e3913b736f4 100644 (file)
 
 #define STACK_MAGIC    0xdeadbeef
 
-/**
- * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
- * @x: value to repeat
- *
- * NOTE: @x is not checked for > 0xff; larger values produce odd results.
- */
-#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
-
 /* generic data direction definitions */
 #define READ                   0
 #define WRITE                  1
diff --git a/include/linux/wordpart.h b/include/linux/wordpart.h
new file mode 100644 (file)
index 0000000..c9e6bd7
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _LINUX_WORDPART_H
+#define _LINUX_WORDPART_H
+/**
+ * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
+ * @x: value to repeat
+ *
+ * NOTE: @x is not checked for > 0xff; larger values produce odd results.
+ */
+#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
+
+#endif // _LINUX_WORDPART_H