From: Miguel Ojeda <ojeda@kernel.org>
To: Benno Lossin <lossin@kernel.org>, Gary Guo <gary@garyguo.net>,
Miguel Ojeda <ojeda@kernel.org>
Cc: rust-for-linux@vger.kernel.org, "Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
stable@vger.kernel.org
Subject: [PATCH v2] rust: init: clean Rust 1.102.0's `clippy::large_unopt_stack_frames` lint
Date: Sun, 29 Nov 2026 15:35:28 +0100 [thread overview]
Message-ID: <20261129143528.142974-1-ojeda@kernel.org> (raw)
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
reply other threads:[~2026-11-29 14:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129143528.142974-1-ojeda@kernel.org \
--to=ojeda@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=lossin@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox