* [PATCH v2] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
@ 2026-11-29 14:35 Miguel Ojeda
2026-11-29 20:02 ` Gary Guo
0 siblings, 1 reply; 2+ messages in thread
From: Miguel Ojeda @ 2026-11-29 14:35 UTC (permalink / raw)
To: Benno Lossin, Gary Guo, Miguel Ojeda
Cc: rust-for-linux, Boqun Feng, Björn Roy Baron,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, stable
Starting with Rust 1.102.0 (expected 2027-02-04), Clippy renames the
`large_stack_frames` lint to `large_unopt_stack_frames` and moves it to
`suspicious` from `nursery` [1], and thus we start to see it in the
examples of `try_init!` and `try_pin_init!`:
warning: closure generated by this macro may allocate a lot of stack space
--> rust/doctests_kernel_generated.rs:6716:9
|
6716 | / try_init!(Self {
6717 | | big: KBox::init(init_zeroed(), GFP_KERNEL)?,
6718 | | small: [0; 1024 * 1024],
6719 | | }? Error)
| |_________________^
|
= help: for further information visit https://clippy.rust-lang.org/main/index.html#large_unopt_stack_frames
= note: `-W clippy::large-unopt-stack-frames` implied by `-W clippy::all`
= help: to override `-W clippy::all` add `#[allow(clippy::large_unopt_stack_frames)]`
The 1 MiB array is initialized by value, thus the closure that is
generated would need to hold it in its stack frame (without optimizations,
which is what the lint goes by).
Thus make it actually small (128 bytes), as the name of the field says,
which allows to keep initializing it by value.
Cc: stable@vger.kernel.org # 6.12.x (Rust is pinned in older LTSs)
Link: https://github.com/rust-lang/rust-clippy/pull/17749 [1]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
v2:
- Made `small` actually small (128 bytes) and kept the by-value
initialization instead.
v1: https://lore.kernel.org/rust-for-linux/20261126131456.87524-1-ojeda@kernel.org/
rust/kernel/init.rs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index 1fdc3963e3e3..a8df7b6a2749 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -204,14 +204,14 @@ fn init<E>(init: impl Init<T, E>, flags: Flags) -> error::Result<Self>
/// use pin_init::init_zeroed;
/// struct BigBuf {
/// big: KBox<[u8; 1024 * 1024 * 1024]>,
-/// small: [u8; 1024 * 1024],
+/// small: [u8; 128],
/// }
///
/// impl BigBuf {
/// fn new() -> impl Init<Self, Error> {
/// try_init!(Self {
/// big: KBox::init(init_zeroed(), GFP_KERNEL)?,
-/// small: [0; 1024 * 1024],
+/// small: [0; 128],
/// }? Error)
/// }
/// }
@@ -255,7 +255,7 @@ macro_rules! try_init {
/// #[pin_data]
/// struct BigBuf {
/// big: KBox<[u8; 1024 * 1024 * 1024]>,
-/// small: [u8; 1024 * 1024],
+/// small: [u8; 128],
/// ptr: *mut u8,
/// }
///
@@ -263,7 +263,7 @@ macro_rules! try_init {
/// fn new() -> impl PinInit<Self, Error> {
/// try_pin_init!(Self {
/// big: KBox::init(init_zeroed(), GFP_KERNEL)?,
-/// small: [0; 1024 * 1024],
+/// small: [0; 128],
/// ptr: core::ptr::null_mut(),
/// }? Error)
/// }
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
2026-11-29 14:35 [PATCH v2] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint Miguel Ojeda
@ 2026-11-29 20:02 ` Gary Guo
0 siblings, 0 replies; 2+ messages in thread
From: Gary Guo @ 2026-11-29 20:02 UTC (permalink / raw)
To: Benno Lossin, Miguel Ojeda
Cc: rust-for-linux, Boqun Feng, Björn Roy Baron,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, stable
On Sun, 29 Nov 2026 15:35:28 +0100, Miguel Ojeda wrote:
> Starting with Rust 1.102.0 (expected 2027-02-04), Clippy renames the
> `large_stack_frames` lint to `large_unopt_stack_frames` and moves it to
> `suspicious` from `nursery` [1], and thus we start to see it in the
> examples of `try_init!` and `try_pin_init!`:
>
> warning: closure generated by this macro may allocate a lot of stack space
> --> rust/doctests_kernel_generated.rs:6716:9
> |
> 6716 | / try_init!(Self {
> 6717 | | big: KBox::init(init_zeroed(), GFP_KERNEL)?,
> 6718 | | small: [0; 1024 * 1024],
> 6719 | | }? Error)
> | |_________________^
> |
> = help: for further information visit https://clippy.rust-lang.org/main/index.html#large_unopt_stack_frames
> = note: `-W clippy::large-unopt-stack-frames` implied by `-W clippy::all`
> = help: to override `-W clippy::all` add `#[allow(clippy::large_unopt_stack_frames)]`
>
> [...]
Applied, thanks!
[1/1] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
commit: 246f6b0262bae1c4a8145804713c0a338f907bc4
Best regards,
--
Gary Guo <gary@garyguo.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 20:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 14:35 [PATCH v2] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint Miguel Ojeda
2026-11-29 20:02 ` Gary Guo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.