<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/rust/kernel/bitfield.rs, 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>rust: bitfield: always inline test conversions</title>
<updated>2026-08-10T04:58:31+00:00</updated>
<author>
<name>Antoni Boucher</name>
<email>bouanto@zoho.com</email>
</author>
<published>2026-08-07T17:50:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=359af525750d3c13f2d500bf9425c945c9467ce3'/>
<id>359af525750d3c13f2d500bf9425c945c9467ce3</id>
<content type='text'>
When using the Rust GCC backend (i.e. `rustc_codegen_gcc`), GCC does not
inline enough these `Bounded::from_expr` calls:

    /usr/bin/x86_64-linux-gnu-ld.bfd: rust/kernel.o: in function `&lt;kernel::num::bounded::Bounded&lt;u16, 2&gt; as core::convert::From&lt;kernel::bitfield::tests::Priority&gt;&gt;::from':
    fake.c:(.text.unlikely+0x7be): undefined reference to `rust_build_error'

    /usr/bin/x86_64-linux-gnu-ld.bfd: rust/kernel.o: in function `&lt;kernel::num::bounded::Bounded&lt;u64, 4&gt; as core::convert::From&lt;kernel::bitfield::tests::MemoryType&gt;&gt;::from':
    fake.c:(.text.unlikely+0x90d): undefined reference to `rust_build_error'

Thus, similar to commit bc197e24a3ac ("rust: num: bounded: Always inline
fits_within and from_expr"), mark them as `#[inline(always)]`.

[ Reworded to add the error and to follow our usual style and sent on
  behalf of Antoni, who found this during his work to support Rust for
  Linux with the GCC backend, i.e. with `rustc_codegen_gcc`. - Miguel ]

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Antoni Boucher &lt;bouanto@zoho.com&gt;
Acked-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://patch.msgid.link/20260807175012.142083-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When using the Rust GCC backend (i.e. `rustc_codegen_gcc`), GCC does not
inline enough these `Bounded::from_expr` calls:

    /usr/bin/x86_64-linux-gnu-ld.bfd: rust/kernel.o: in function `&lt;kernel::num::bounded::Bounded&lt;u16, 2&gt; as core::convert::From&lt;kernel::bitfield::tests::Priority&gt;&gt;::from':
    fake.c:(.text.unlikely+0x7be): undefined reference to `rust_build_error'

    /usr/bin/x86_64-linux-gnu-ld.bfd: rust/kernel.o: in function `&lt;kernel::num::bounded::Bounded&lt;u64, 4&gt; as core::convert::From&lt;kernel::bitfield::tests::MemoryType&gt;&gt;::from':
    fake.c:(.text.unlikely+0x90d): undefined reference to `rust_build_error'

Thus, similar to commit bc197e24a3ac ("rust: num: bounded: Always inline
fits_within and from_expr"), mark them as `#[inline(always)]`.

[ Reworded to add the error and to follow our usual style and sent on
  behalf of Antoni, who found this during his work to support Rust for
  Linux with the GCC backend, i.e. with `rustc_codegen_gcc`. - Miguel ]

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Antoni Boucher &lt;bouanto@zoho.com&gt;
Acked-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://patch.msgid.link/20260807175012.142083-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: bitfield: mark `Debug` impl as `#[inline]`</title>
<updated>2026-06-16T23:32:56+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-06-11T19:05:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=f09d2312d1d44a8b8c9d3bfd33acfe930a6d8250'/>
<id>f09d2312d1d44a8b8c9d3bfd33acfe930a6d8250</id>
<content type='text'>
A `Debug` impl is for debugging and is normally not used, and therefore
should ideally not be code-generated unless used. However, Rust has no way
of knowing if a dependent crate is going to use the trait impl or not, so
unless it is marked as `#[inline]`, it will be code-generated in the
defining crate (as it is not generic).

Mark the impl generated by bitfield macro `#[inline]`, so they do not stay
in the binary unless used.

This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Fixes: b7b8b4ccdad4 ("rust: extract `bitfield!` macro from `register!`")
Acked-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Link: https://patch.msgid.link/20260611190555.2298991-1-gary@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
A `Debug` impl is for debugging and is normally not used, and therefore
should ideally not be code-generated unless used. However, Rust has no way
of knowing if a dependent crate is going to use the trait impl or not, so
unless it is marked as `#[inline]`, it will be code-generated in the
defining crate (as it is not generic).

Mark the impl generated by bitfield macro `#[inline]`, so they do not stay
in the binary unless used.

This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Fixes: b7b8b4ccdad4 ("rust: extract `bitfield!` macro from `register!`")
Acked-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Link: https://patch.msgid.link/20260611190555.2298991-1-gary@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: bitfield: Add KUnit tests for bitfield</title>
<updated>2026-06-09T02:13:07+00:00</updated>
<author>
<name>Joel Fernandes</name>
<email>joelagnelf@nvidia.com</email>
</author>
<published>2026-06-06T12:43:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7f502747bc0019acf40d620b50a98b62851fa0cc'/>
<id>7f502747bc0019acf40d620b50a98b62851fa0cc</id>
<content type='text'>
Add KUnit tests to make sure the macro is working correctly. The unit
tests are put behind the new `RUST_BITFIELD_KUNIT_TEST` Kconfig option.

Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Reviewed-by: Eliot Courtney &lt;ecourtney@nvidia.com&gt;
Signed-off-by: Joel Fernandes &lt;joelagnelf@nvidia.com&gt;
[acourbot:
- Use a consistent test axis where each test focuses on a single thing.
- Rename members to generic name including range for readability.
- Add test exercising `try_with`.
- Add test checking that unallocated bits are left untouched.
]
Co-developed-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Yury Norov &lt;ynorov@nvidia.com&gt;
Link: https://patch.msgid.link/20260606-bitfield-v5-2-b92188820914@nvidia.com
[ Prefixed test suite name with `rust_` as mentioned. Markdown-formatted
  a few comments with Markdown. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add KUnit tests to make sure the macro is working correctly. The unit
tests are put behind the new `RUST_BITFIELD_KUNIT_TEST` Kconfig option.

Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Reviewed-by: Eliot Courtney &lt;ecourtney@nvidia.com&gt;
Signed-off-by: Joel Fernandes &lt;joelagnelf@nvidia.com&gt;
[acourbot:
- Use a consistent test axis where each test focuses on a single thing.
- Rename members to generic name including range for readability.
- Add test exercising `try_with`.
- Add test checking that unallocated bits are left untouched.
]
Co-developed-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Yury Norov &lt;ynorov@nvidia.com&gt;
Link: https://patch.msgid.link/20260606-bitfield-v5-2-b92188820914@nvidia.com
[ Prefixed test suite name with `rust_` as mentioned. Markdown-formatted
  a few comments with Markdown. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: extract `bitfield!` macro from `register!`</title>
<updated>2026-06-09T02:12:51+00:00</updated>
<author>
<name>Alexandre Courbot</name>
<email>acourbot@nvidia.com</email>
</author>
<published>2026-06-06T12:43:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=b7b8b4ccdad45a59aafa5cfc32a51fe1ee5cb680'/>
<id>b7b8b4ccdad45a59aafa5cfc32a51fe1ee5cb680</id>
<content type='text'>
Extract the bitfield-defining part of the `register!` macro into an
independent macro used to define bitfield types with bounds-checked
accessors.

Each field is represented as a `Bounded` of the appropriate bit width,
ensuring field values are never silently truncated.

Fields can optionally be converted to/from custom types, either fallibly
or infallibly.

Appropriate documentation is also added, and a MAINTAINERS entry created
for the new module.

Two minor fixups are also applied: the private accessors are inlined,
and a couple of missing fully qualified types in the macro are fixed.

Acked-by: Yury Norov &lt;ynorov@nvidia.com&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Yury Norov &lt;ynorov@nvidia.com&gt;
Link: https://patch.msgid.link/20260606-bitfield-v5-1-b92188820914@nvidia.com
[ Added some more intra-doc links. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Extract the bitfield-defining part of the `register!` macro into an
independent macro used to define bitfield types with bounds-checked
accessors.

Each field is represented as a `Bounded` of the appropriate bit width,
ensuring field values are never silently truncated.

Fields can optionally be converted to/from custom types, either fallibly
or infallibly.

Appropriate documentation is also added, and a MAINTAINERS entry created
for the new module.

Two minor fixups are also applied: the private accessors are inlined,
and a couple of missing fully qualified types in the macro are fixed.

Acked-by: Yury Norov &lt;ynorov@nvidia.com&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Reviewed-by: Yury Norov &lt;ynorov@nvidia.com&gt;
Link: https://patch.msgid.link/20260606-bitfield-v5-1-b92188820914@nvidia.com
[ Added some more intra-doc links. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
