<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/rust/pin-init, 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: pin_init: internal: use `loop {}` to produce never value</title>
<updated>2026-05-29T20:58:36+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-05-08T15:29:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d2f309227952e73966682f348161094e40eb6440'/>
<id>d2f309227952e73966682f348161094e40eb6440</id>
<content type='text'>
In the `init!`/`pin_init!` macros, we rely on a trick that assigns never
(`!`) values to all mentioned fields in never-executed code to let the
compiler check that all fields have been initialized.

Currently we use `::core::panic!()` to produce this value, but before Rust
1.91.0, it creates outlined `panic_cold_explicit` functions which do not
get removed by the optimizer, thus leaving dead code behind in the binary.
This has been fixed by [1], which lands in Rust 1.91.0+, higher than the
kernel minimum version 1.85.0.

This causes ~200 dead `panic_cold_explicit` instances being included in the
binary, with ~90 of them from nova-core's usage of pin-init.

Work around the issue by using `loop {}` which creates the never value
without macro expansion or function call at all. All instances of
`panic_cold_explicit` outside libcore are removed by this change in my
kernel build.

Link: https://github.com/rust-lang/rust/pull/145304 [1]
Link: https://patch.msgid.link/20260508152950.833635-1-gary@kernel.org
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In the `init!`/`pin_init!` macros, we rely on a trick that assigns never
(`!`) values to all mentioned fields in never-executed code to let the
compiler check that all fields have been initialized.

Currently we use `::core::panic!()` to produce this value, but before Rust
1.91.0, it creates outlined `panic_cold_explicit` functions which do not
get removed by the optimizer, thus leaving dead code behind in the binary.
This has been fixed by [1], which lands in Rust 1.91.0+, higher than the
kernel minimum version 1.85.0.

This causes ~200 dead `panic_cold_explicit` instances being included in the
binary, with ~90 of them from nova-core's usage of pin-init.

Work around the issue by using `loop {}` which creates the never value
without macro expansion or function call at all. All instances of
`panic_cold_explicit` outside libcore are removed by this change in my
kernel build.

Link: https://github.com/rust-lang/rust/pull/145304 [1]
Link: https://patch.msgid.link/20260508152950.833635-1-gary@kernel.org
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: remove `E` from `InitClosure`</title>
<updated>2026-05-29T20:34:53+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-05-27T17:19:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=f85906616ec70d1d0178073b16ebd1c7f6ff1ee7'/>
<id>f85906616ec70d1d0178073b16ebd1c7f6ff1ee7</id>
<content type='text'>
Move `E` from type to trait impl block. This greatly shortens the
monomorphized type names. The `__pinned_init` function name is only
slightly shortened as it still encodes the `E` as part of `PinInit&lt;T, E&gt;`
in the symbol.

`T` cannot be moved to trait impl block otherwise it will start to conflict
with the `impl Init&lt;T&gt; for T` as Rust cannot deduce that there're no types
that fulfill `T: FnOnce(*mut T)`.

Link: https://patch.msgid.link/20260527-pin-init-sync-v1-6-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Move `E` from type to trait impl block. This greatly shortens the
monomorphized type names. The `__pinned_init` function name is only
slightly shortened as it still encodes the `E` as part of `PinInit&lt;T, E&gt;`
in the symbol.

`T` cannot be moved to trait impl block otherwise it will start to conflict
with the `impl Init&lt;T&gt; for T` as Rust cannot deduce that there're no types
that fulfill `T: FnOnce(*mut T)`.

Link: https://patch.msgid.link/20260527-pin-init-sync-v1-6-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: move `InitClosure` out from `__internal`</title>
<updated>2026-05-29T20:34:53+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-05-27T17:19:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=79bc923ae2a60a227907697abab4ed26c3fc3670'/>
<id>79bc923ae2a60a227907697abab4ed26c3fc3670</id>
<content type='text'>
The `__internal` module is for exposing internal items publicly to
procedural macros (pin-init-internal). Types that are crate-local only can
just have proper visibility and does not need to be in `__internal`.

The type name of `InitClosure` can often shows up in symbol names, this
reduces the length slightly.

Link: https://patch.msgid.link/20260527-pin-init-sync-v1-5-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The `__internal` module is for exposing internal items publicly to
procedural macros (pin-init-internal). Types that are crate-local only can
just have proper visibility and does not need to be in `__internal`.

The type name of `InitClosure` can often shows up in symbol names, this
reduces the length slightly.

Link: https://patch.msgid.link/20260527-pin-init-sync-v1-5-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: docs: fix typos in MaybeZeroable documentation</title>
<updated>2026-05-29T20:34:53+00:00</updated>
<author>
<name>Xiaobo Liu</name>
<email>cppcoffee@gmail.com</email>
</author>
<published>2026-05-27T17:19:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=2a02b4f96f7bb77ae4cef5d41494f83d01d022dd'/>
<id>2a02b4f96f7bb77ae4cef5d41494f83d01d022dd</id>
<content type='text'>
Signed-off-by: Xiaobo Liu &lt;cppcoffee@gmail.com&gt;
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-4-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Signed-off-by: Xiaobo Liu &lt;cppcoffee@gmail.com&gt;
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-4-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: internal: suppress `non_snake_case` lint in `[pin_]init!`</title>
<updated>2026-05-29T20:34:53+00:00</updated>
<author>
<name>Mirko Adzic</name>
<email>adzicmirko97@gmail.com</email>
</author>
<published>2026-05-27T17:19:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=5423ef9d4db852835746001d0840231227bb0e39'/>
<id>5423ef9d4db852835746001d0840231227bb0e39</id>
<content type='text'>
Allows `non_snake_case` lint on local variables generated in `[pin_]init!`.

Conceptually the identifiers in `[pin_]init!` just references the field
names, and are not defining them, so the warning should not be generated,
similar to how constructing a struct with non-snake-case field names do no
generate these warnings.

Reported-by: Gary Guo &lt;gary@garyguo.net&gt;
Closes: https://github.com/Rust-for-Linux/pin-init/issues/125
Closes: https://lore.kernel.org/rust-for-linux/DGTBJBIVFZ2K.2F1ZEFGY0G7NK@garyguo.net/
Fixes: 42415d163e5d ("rust: pin-init: add references to previously initialized fields")
Signed-off-by: Mirko Adzic &lt;adzicmirko97@gmail.com&gt;
[ Reworded commit message - Gary ]
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-3-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Allows `non_snake_case` lint on local variables generated in `[pin_]init!`.

Conceptually the identifiers in `[pin_]init!` just references the field
names, and are not defining them, so the warning should not be generated,
similar to how constructing a struct with non-snake-case field names do no
generate these warnings.

Reported-by: Gary Guo &lt;gary@garyguo.net&gt;
Closes: https://github.com/Rust-for-Linux/pin-init/issues/125
Closes: https://lore.kernel.org/rust-for-linux/DGTBJBIVFZ2K.2F1ZEFGY0G7NK@garyguo.net/
Fixes: 42415d163e5d ("rust: pin-init: add references to previously initialized fields")
Signed-off-by: Mirko Adzic &lt;adzicmirko97@gmail.com&gt;
[ Reworded commit message - Gary ]
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-3-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: internal: suppress `non_snake_case` lint in `#[pin_data]`</title>
<updated>2026-05-29T20:34:53+00:00</updated>
<author>
<name>Mirko Adzic</name>
<email>adzicmirko97@gmail.com</email>
</author>
<published>2026-05-27T17:19:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=e6405dca10de4136a880d218b015663a41d92a54'/>
<id>e6405dca10de4136a880d218b015663a41d92a54</id>
<content type='text'>
Allows `non_snake_case` lint on struct fields generated by `#[pin_data]`.

Since the same warning will be reported by the compiler on the struct
definition, having extra warnings for the generated code is unnecessary
and confusing.

Signed-off-by: Mirko Adzic &lt;adzicmirko97@gmail.com&gt;
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-2-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Allows `non_snake_case` lint on struct fields generated by `#[pin_data]`.

Since the same warning will be reported by the compiler on the struct
definition, having extra warnings for the generated code is unnecessary
and confusing.

Signed-off-by: Mirko Adzic &lt;adzicmirko97@gmail.com&gt;
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-2-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: internal: pin_data: filter non-`#[cfg]` attr in generated code</title>
<updated>2026-05-29T20:34:53+00:00</updated>
<author>
<name>Martin Kletzander</name>
<email>mkletzan@redhat.com</email>
</author>
<published>2026-05-27T17:19:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=28ba76f374bf5fec9e5bf5035ffe90e4c6b05682'/>
<id>28ba76f374bf5fec9e5bf5035ffe90e4c6b05682</id>
<content type='text'>
When using a macro with custom attributes in a `#[pin_data]` struct it
can mess up the generated code. The generated code needs nothing more than
the `#[cfg]` attribute, thus strip away all other attributes.

[ Rebased and updated to only include `#[cfg]` instead of both `#[cfg]` and
  `#[doc]`; doc is not needed for the generated hidden items. - Gary ]

Signed-off-by: Martin Kletzander &lt;mkletzan@redhat.com&gt;
Co-developed-by: Gary Guo &lt;gary@garyguo.net&gt;
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-1-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When using a macro with custom attributes in a `#[pin_data]` struct it
can mess up the generated code. The generated code needs nothing more than
the `#[cfg]` attribute, thus strip away all other attributes.

[ Rebased and updated to only include `#[cfg]` instead of both `#[cfg]` and
  `#[doc]`; doc is not needed for the generated hidden items. - Gary ]

Signed-off-by: Martin Kletzander &lt;mkletzan@redhat.com&gt;
Co-developed-by: Gary Guo &lt;gary@garyguo.net&gt;
Link: https://patch.msgid.link/20260527-pin-init-sync-v1-1-e20335ed2501@garyguo.net
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: internal: project using full slot</title>
<updated>2026-05-18T11:21:28+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-05-12T12:09:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=6fb5912c92926025a7e205d53feb73c3478c79a1'/>
<id>6fb5912c92926025a7e205d53feb73c3478c79a1</id>
<content type='text'>
Instead of projecting using pointer to a field project the full slot. This
further shifts the code generation from the initializer site to the struct
definition site, which means less code is generated overall.

It also makes the safety comment easier to justify, as now the projection
is done by the `#[pin_data]` macro which has full visibility of pinnedness
of fields.

The field alignment could also be checked on the `#[pin_data]` side;
however, since `init!()` macro works for other type of structs, we cannot
remove the alignment check from `init!`/`pin_init!` side anyway, so I opted
to still keep the alignment check in init.rs.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Instead of projecting using pointer to a field project the full slot. This
further shifts the code generation from the initializer site to the struct
definition site, which means less code is generated overall.

It also makes the safety comment easier to justify, as now the projection
is done by the `#[pin_data]` macro which has full visibility of pinnedness
of fields.

The field alignment could also be checked on the `#[pin_data]` side;
however, since `init!()` macro works for other type of structs, we cannot
remove the alignment check from `init!`/`pin_init!` side anyway, so I opted
to still keep the alignment check in init.rs.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: internal: project slots instead of references</title>
<updated>2026-05-18T11:21:13+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-05-12T12:09:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=5483a97dd2dfcaf8540dba0a80b68a400c4c1861'/>
<id>5483a97dd2dfcaf8540dba0a80b68a400c4c1861</id>
<content type='text'>
By projecting slots, the `pin_init!` and `init!` code path can be more
unified. This also reduces the amount of macro-generated code and shifts
them to the shared infrastructure.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
By projecting slots, the `pin_init!` and `init!` code path can be more
unified. This also reduces the amount of macro-generated code and shifts
them to the shared infrastructure.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: pin-init: internal: make `make_closure` inherent methods</title>
<updated>2026-05-18T11:18:06+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-05-12T12:09:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=57b0a0d7e5a063edceb50bffa648b49591112896'/>
<id>57b0a0d7e5a063edceb50bffa648b49591112896</id>
<content type='text'>
The `InitData` and `PinData` traits do not need to exist, the inference
helpers could be inherent methods instead.

There is no risk for calling the wrong methods even when user defines it,
as inherent methods take priority over trait methods.

With this change, it unlocks the possibility of attaching additional bounds
to the method per type, which is not possible for trait methods.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The `InitData` and `PinData` traits do not need to exist, the inference
helpers could be inherent methods instead.

There is no risk for calling the wrong methods even when user defines it,
as inherent methods take priority over trait methods.

With this change, it unlocks the possibility of attaching additional bounds
to the method per type, which is not possible for trait methods.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
</pre>
</div>
</content>
</entry>
</feed>
