linux/tools/include/linux
Yury Norov 1c88ceb09d bitfield: get rid of __MAKE_OP machinery
The __MAKE_OP machinery hides the fixed-width bitfield helper definitions
from source searches and makes the end result highly obscured and largely
uncontrolled.

This follows earlier discussions about making these helpers easier to
find: [1], [2].

Move the explicit helpers and their shared checks into
linux/bitfield-fix-width.h in both the kernel and tools headers, and
include it from bitfield.h to preserve existing users.

The repeated overflow check is factored into __assert_field(), preserving
the original condition and compile-time diagnostics.

With GCC 15.2.0 and x86-64 defconfig plus the bitfield KUnit tests, the
before/after kernel builds are binary identical.

The __MAKE_OP generates the following 40 functions (including the direct
____MAKE_OP(u8,u8,,) invocation):

  u8_encode_bits()
  u8_replace_bits()
  u8p_replace_bits()
  u8_get_bits()
  le16_encode_bits()
  le16_replace_bits() [dead code]
  le16p_replace_bits()
  le16_get_bits()
  be16_encode_bits()
  be16_replace_bits() [dead code]
  be16p_replace_bits() [dead code]
  be16_get_bits()
  u16_encode_bits()
  u16_replace_bits()
  u16p_replace_bits()
  u16_get_bits()
  le32_encode_bits()
  le32_replace_bits() [dead code]
  le32p_replace_bits()
  le32_get_bits()
  be32_encode_bits()
  be32_replace_bits() [dead code]
  be32p_replace_bits()
  be32_get_bits()
  u32_encode_bits()
  u32_replace_bits()
  u32p_replace_bits()
  u32_get_bits()
  le64_encode_bits()
  le64_replace_bits() [dead code]
  le64p_replace_bits() [dead code]
  le64_get_bits()
  be64_encode_bits()
  be64_replace_bits() [dead code]
  be64p_replace_bits() [dead code]
  be64_get_bits()
  u64_encode_bits()
  u64_replace_bits()
  u64p_replace_bits()
  u64_get_bits()

Functions marked with [dead code] have no in-tree callers and are
removed by this change.

Link: https://lore.kernel.org/all/20250214073402.0129e259@kernel.org/ [1]
Link: https://lore.kernel.org/all/aeub59FBHbCy-KKP@yury/ [2]
Assisted-by: OpenAI Codex
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
2026-09-21 12:28:21 -04:00
..
sched XArray: Add calls to might_alloc() 2022-07-10 21:17:30 -04:00
unaligned
align.h tools: move alignment-related macros to new <linux/align.h> 2024-04-01 10:49:28 +01:00
args.h selftests/bpf: Add simple strscpy() implementation 2026-02-23 18:40:07 -08:00
arm-smccc.h tools: Import ARM SMCCC definitions 2022-05-03 21:30:19 +01:00
atomic.h tools/include: implement a couple of atomic_t ops 2025-09-13 16:55:24 -07:00
bitfield-fix-width.h bitfield: get rid of __MAKE_OP machinery 2026-09-21 12:28:21 -04:00
bitfield.h bitfield: get rid of __MAKE_OP machinery 2026-09-21 12:28:21 -04:00
bitmap.h tools: bitmap: add missing bitmap_copy() implementation 2026-04-05 13:53:41 -07:00
bitops.h asm-generic cleanups for 6.10 2024-05-20 15:18:34 -07:00
bits.h bitmap: Replace __ASSEMBLY__ with __ASSEMBLER__ in header files 2026-07-22 15:38:36 -04:00
btf_ids.h tools/bpf: Sync btf_ids.h to tools 2026-06-25 18:21:31 -07:00
bug.h
build_bug.h tools headers: Synchronize linux/build_bug.h with the kernel sources 2026-03-22 18:34:39 -03:00
cache.h
cfi_types.h tools headers: kcfi: rename missed CONFIG_CFI_CLANG 2025-10-07 08:21:33 -07:00
compiler_types.h Updates for the VDSO subsystem: 2026-02-10 17:02:23 -08:00
compiler-context-analysis.h tools: Update context analysis macros in compiler_types.h 2026-01-28 09:25:45 +01:00
compiler-gcc.h Improve consistency of '#error' directive messages 2024-11-11 17:17:04 -08:00
compiler.h tools/compiler: match glibc 2.42 definition of __attribute_const__ 2026-08-03 21:10:08 -07:00
const.h compiler.h: move __is_constexpr() to compiler.h 2023-10-18 14:43:22 -07:00
container_of.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
coresight-pmu.h perf cs-etm: Sync coresight-pmu.h header with the kernel sources 2026-03-10 09:52:00 -03:00
ctype.h
debugfs.h
delay.h
err.h docs: move x86 documentation into Documentation/arch/ 2023-03-30 12:58:51 -06:00
export.h
filter.h tools: Ensure tools copy of linux/filter.h exports the UAPI 2026-08-06 13:13:12 +00:00
find.h tools: sync find_bit() implementation 2022-09-21 12:21:44 -07:00
ftrace.h
gfp_types.h mm: remove the __GFP_NO_OBJ_EXT flag 2026-07-30 19:40:44 -07:00
gfp.h tools/testing: fix testing/vma and testing/radix-tree build 2026-03-04 09:44:22 -08:00
hash.h
hashtable.h
init.h memblock test: add the definition of __setup() 2024-08-06 08:21:25 +03:00
interrupt.h
interval_tree_generic.h interval_tree: Fix ITSTATIC usage for *_subtree_search() 2025-10-14 14:45:22 -07:00
io.h tools headers: Import asm-generic MMIO helpers 2025-08-27 12:14:06 -06:00
jhash.h
kallsyms.h kallsyms: fix build without execinfo 2025-07-09 21:07:51 -07:00
kasan-tags.h tools: arm64: Update sysreg.h header files 2025-01-12 12:50:11 +00:00
kconfig.h
kern_levels.h
kernel.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
linkage.h more s390 updates for 6.12 merge window 2024-09-28 09:11:46 -07:00
list_sort.h
list.h tools/lib: Add list_is_first() 2026-01-21 21:54:59 -03:00
livepatch_external.h objtool/klp: Introduce klp diff subcommand for diffing object files 2025-10-14 14:50:18 -07:00
log2.h
math.h
math64.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
mm.h mm: move free_reserved_area() to mm/memblock.c 2026-04-01 11:19:46 +03:00
module.h
moduleparam.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
mutex.h
nmi.h
numa.h memblock tests: fix implicit declaration of function 'numa_valid_node' 2024-07-05 11:24:47 +03:00
objtool_types.h objtool/headers: Sync tools/include/linux/objtool_types.h with include/linux/objtool_types.h 2026-08-11 10:44:38 +02:00
overflow.h tools/include: include stdint.h for SIZE_MAX in overflow.h 2026-07-01 19:02:56 -07:00
panic.h memblock tests: fix undefined reference to `panic' 2024-04-04 11:08:33 +03:00
pci_ids.h tools headers: Add symlink to linux/pci_ids.h 2025-08-27 12:14:07 -06:00
pfn.h mm/memblock: introduce a new helper memblock_estimated_nr_free_pages() 2024-08-11 19:18:52 +03:00
poison.h slab: delete useless RED_INACTIVE and RED_ACTIVE 2024-06-24 21:41:41 +02:00
prandom.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
rbtree_augmented.h tools lib rbtree: pick some improvements from the kernel rbtree code 2024-05-08 08:41:27 -07:00
rbtree.h
rcu.h
refcount.h mm: make vma cache SLAB_TYPESAFE_BY_RCU 2025-03-16 22:06:21 -07:00
ring_buffer.h tools: Optimize ring buffer for riscv 2024-09-20 01:46:47 -07:00
rwsem.h maple_tree: update check_forking() and bench_forking() 2023-12-10 16:51:33 -08:00
seq_file.h memblock tests: fix warning ‘struct seq_file’ declared inside parameter list 2023-09-14 10:51:28 +03:00
sizes.h
slab.h mm/slab: improve kmem_cache_alloc_bulk 2026-06-03 18:20:43 +02:00
spinlock.h maple_tree: introduce {mtree,mas}_lock_nested() 2023-12-10 16:51:31 -08:00
static_call_types.h static_call / jump_label: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2026-07-31 10:32:24 +02:00
string.h objtool/klp: Introduce klp diff subcommand for diffing object files 2025-10-14 14:50:18 -07:00
stringify.h
time64.h
types.h tools: linux/types.h: Add 128-bit integer types for arm64 UAPI structures 2026-07-21 21:53:02 +00:00
unaligned.h tools headers: Remove unneeded ignoring of warnings in unaligned.h 2026-01-14 08:56:41 +01:00
zalloc.h