Commit 66a5c40f authored by Tanzir Hasan's avatar Tanzir Hasan Committed by Kees Cook

kernel.h: removed REPEAT_BYTE from kernel.h

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: default avatarAl Viro <viro@zeniv.linux.org.uk>
Suggested-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarTanzir Hasan <tanzirh@google.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20231226-libstringheader-v6-1-80aa08c7652c@google.comSigned-off-by: default avatarKees Cook <keescook@chromium.org>
parent 735b7636
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
* Little-endian word-at-a-time zero byte handling. * Little-endian word-at-a-time zero byte handling.
* Heavily based on the x86 algorithm. * Heavily based on the x86 algorithm.
*/ */
#include <linux/kernel.h> #include <linux/bitops.h>
#include <linux/wordpart.h>
struct word_at_a_time { struct word_at_a_time {
const unsigned long one_bits, high_bits; const unsigned long one_bits, high_bits;
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#ifndef __AARCH64EB__ #ifndef __AARCH64EB__
#include <linux/kernel.h> #include <linux/bitops.h>
#include <linux/wordpart.h>
struct word_at_a_time { struct word_at_a_time {
const unsigned long one_bits, high_bits; const unsigned long one_bits, high_bits;
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
/* /*
* Word-at-a-time interfaces for PowerPC. * Word-at-a-time interfaces for PowerPC.
*/ */
#include <linux/bitops.h>
#include <linux/kernel.h> #include <linux/wordpart.h>
#include <asm/asm-compat.h> #include <asm/asm-compat.h>
#include <asm/extable.h> #include <asm/extable.h>
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
#include <asm/asm-extable.h> #include <asm/asm-extable.h>
#include <linux/kernel.h> #include <linux/bitops.h>
#include <linux/wordpart.h>
struct word_at_a_time { struct word_at_a_time {
const unsigned long one_bits, high_bits; const unsigned long one_bits, high_bits;
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
#ifndef _ASM_WORD_AT_A_TIME_H #ifndef _ASM_WORD_AT_A_TIME_H
#define _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/asm-extable.h>
#include <asm/bitsperlong.h> #include <asm/bitsperlong.h>
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifdef CONFIG_CPU_BIG_ENDIAN #ifdef CONFIG_CPU_BIG_ENDIAN
# include <asm-generic/word-at-a-time.h> # include <asm-generic/word-at-a-time.h>
#else #else
#include <linux/bitops.h>
#include <linux/wordpart.h>
/* /*
* Little-endian version cribbed from x86. * Little-endian version cribbed from x86.
*/ */
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
#ifndef _ASM_WORD_AT_A_TIME_H #ifndef _ASM_WORD_AT_A_TIME_H
#define _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 * This is largely generic for little-endian machines, but the
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <linux/kern_levels.h> #include <linux/kern_levels.h>
#include <linux/kstrtox.h> #include <linux/kstrtox.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/wordpart.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/memtype.h> #include <asm/memtype.h>
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/wordpart.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/namei.h> #include <linux/namei.h>
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
#ifndef _ASM_WORD_AT_A_TIME_H #ifndef _ASM_WORD_AT_A_TIME_H
#define _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> #include <asm/byteorder.h>
#ifdef __BIG_ENDIAN #ifdef __BIG_ENDIAN
......
...@@ -39,14 +39,6 @@ ...@@ -39,14 +39,6 @@
#define STACK_MAGIC 0xdeadbeef #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 */ /* generic data direction definitions */
#define READ 0 #define READ 0
#define WRITE 1 #define WRITE 1
......
/* 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment