Skip to content

Commit

Permalink
kernel.h: removed REPEAT_BYTE from kernel.h
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tanzir Hasan authored and Kees Cook committed Feb 1, 2024
1 parent 735b763 commit 66a5c40
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 17 deletions.
3 changes: 2 additions & 1 deletion arch/arm/include/asm/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion arch/arm64/include/asm/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/include/asm/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
3 changes: 2 additions & 1 deletion arch/riscv/include/asm/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion arch/s390/include/asm/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 2 additions & 0 deletions arch/sh/include/asm/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/include/asm/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kvm/mmu/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion include/asm-generic/word-at-a-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@

#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
Expand Down
13 changes: 13 additions & 0 deletions include/linux/wordpart.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 66a5c40

Please sign in to comment.