All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
@ 2026-11-26 13:14 Miguel Ojeda
  2026-11-26 14:53 ` Gary Guo
  0 siblings, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2026-11-26 13:14 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 initialize it in place instead.

Note that the warning only goes away together with commit 5a2024c03eb6
("rust: pin-init: internal: allow `clippy::large_unopt_stack_frames`").

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>
---
 rust/kernel/init.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index 1fdc3963e3e3..238ebb3b1a71 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -211,7 +211,7 @@ fn init<E>(init: impl Init<T, E>, flags: Flags) -> error::Result<Self>
 ///     fn new() -> impl Init<Self, Error> {
 ///         try_init!(Self {
 ///             big: KBox::init(init_zeroed(), GFP_KERNEL)?,
-///             small: [0; 1024 * 1024],
+///             small <- init_zeroed(),
 ///         }? Error)
 ///     }
 /// }
@@ -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 <- init_zeroed(),
 ///             ptr: core::ptr::null_mut(),
 ///         }? Error)
 ///     }

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
  2026-11-26 13:14 [PATCH] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint Miguel Ojeda
@ 2026-11-26 14:53 ` Gary Guo
  2026-11-26 20:17   ` Miguel Ojeda
  0 siblings, 1 reply; 4+ messages in thread
From: Gary Guo @ 2026-11-26 14:53 UTC (permalink / raw)
  To: Miguel Ojeda, Benno Lossin, Gary Guo
  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 Thu Nov 26, 2026 at 1:14 PM GMT, 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)]`
>
> 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 initialize it in place instead.
>
> Note that the warning only goes away together with commit 5a2024c03eb6
> ("rust: pin-init: internal: allow `clippy::large_unopt_stack_frames`").
>
> 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>
> ---
>  rust/kernel/init.rs | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
> index 1fdc3963e3e3..238ebb3b1a71 100644
> --- a/rust/kernel/init.rs
> +++ b/rust/kernel/init.rs
> @@ -211,7 +211,7 @@ fn init<E>(init: impl Init<T, E>, flags: Flags) -> error::Result<Self>
>  ///     fn new() -> impl Init<Self, Error> {
>  ///         try_init!(Self {
>  ///             big: KBox::init(init_zeroed(), GFP_KERNEL)?,
> -///             small: [0; 1024 * 1024],
> +///             small <- init_zeroed(),

Given this is called "small", would it make more sense to just change the size
to, say, 128 and keep the stack init?

Actually, I wonder if we should do:

    big: [u8; 1024 * 1024],
    small: [u8; 128],

and then

    Self {
        big <- init_zeroed(),
        small: [0; 128],
    }

So we demonstrate both big and small init without extra allocation.

Best,
Gary

>  ///         }? Error)
>  ///     }
>  /// }
> @@ -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 <- init_zeroed(),
>  ///             ptr: core::ptr::null_mut(),
>  ///         }? Error)
>  ///     }
>
> base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
  2026-11-26 14:53 ` Gary Guo
@ 2026-11-26 20:17   ` Miguel Ojeda
  2026-11-27  0:12     ` Gary Guo
  0 siblings, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2026-11-26 20:17 UTC (permalink / raw)
  To: Gary Guo
  Cc: Miguel Ojeda, Benno Lossin, 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 Thu, Nov 26, 2026 at 3:54 PM Gary Guo <gary@garyguo.net> wrote:
>
> Given this is called "small", would it make more sense to just change the size
> to, say, 128 and keep the stack init?

Sounds good to me as well. I can send a v2.

> Actually, I wonder if we should do:

Hmm... but then there is no fallibility for the example, no?

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
  2026-11-26 20:17   ` Miguel Ojeda
@ 2026-11-27  0:12     ` Gary Guo
  0 siblings, 0 replies; 4+ messages in thread
From: Gary Guo @ 2026-11-27  0:12 UTC (permalink / raw)
  To: Miguel Ojeda, Gary Guo
  Cc: Miguel Ojeda, Benno Lossin, 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 Thu Nov 26, 2026 at 8:17 PM GMT, Miguel Ojeda wrote:
> On Thu, Nov 26, 2026 at 3:54 PM Gary Guo <gary@garyguo.net> wrote:
>>
>> Given this is called "small", would it make more sense to just change the size
>> to, say, 128 and keep the stack init?
>
> Sounds good to me as well. I can send a v2.
>
>> Actually, I wonder if we should do:
>
> Hmm... but then there is no fallibility for the example, no?

Indeed. Let's keep the box then.

Best,
Gary


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-27  0:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 13:14 [PATCH] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint Miguel Ojeda
2026-11-26 14:53 ` Gary Guo
2026-11-26 20:17   ` Miguel Ojeda
2026-11-27  0:12     ` 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.