<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/tools/include/linux/bitfield-fix-width.h, branch master</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>bitfield: get rid of __MAKE_OP machinery</title>
<updated>2026-09-21T16:28:21+00:00</updated>
<author>
<name>Yury Norov</name>
<email>ynorov@nvidia.com</email>
</author>
<published>2026-09-14T20:49:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=1c88ceb09d5e5506456a625043bc9b35ce86fc41'/>
<id>1c88ceb09d5e5506456a625043bc9b35ce86fc41</id>
<content type='text'>
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 &lt;odaki@rsg.ci.i.u-tokyo.ac.jp&gt;
Acked-by: Jakub Kicinski &lt;kuba@kernel.org&gt;
Signed-off-by: Yury Norov &lt;ynorov@nvidia.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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 &lt;odaki@rsg.ci.i.u-tokyo.ac.jp&gt;
Acked-by: Jakub Kicinski &lt;kuba@kernel.org&gt;
Signed-off-by: Yury Norov &lt;ynorov@nvidia.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
