[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72=38f0dcyt6f3XDf4cZ809cLYghWj+72p+j=w3mFLv=aA@mail.gmail.com>
Date: Thu, 5 Feb 2026 21:55:11 +0100
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Jason Hall <jason.kei.hall@...il.com>
Cc: Joe Perches <joe@...ches.com>, Miguel Ojeda <ojeda@...nel.org>, Dirk Behme <dirk.behme@...il.com>,
Gary Guo <gary@...yguo.net>, Onur Özkan <work@...rozkan.dev>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Boqun Feng <boqun.feng@...il.com>, Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, Dirk Behme <dirk.behme@...bosch.com>,
Andy Whitcroft <apw@...onical.com>, Dwaipayan Ray <dwaipayanray1@...il.com>,
Lukas Bulwahn <lukas.bulwahn@...il.com>
Subject: Re: [PATCH v5] scripts: checkpatch: move Rust-specific lints to
separate file
On Thu, Feb 5, 2026 at 2:42 AM Jason Hall <jason.kei.hall@...il.com> wrote:
>
> Move Rust linting logic into scripts/rust_checkpatch.pl to prevent
> further growth of the main checkpatch.pl script.
>
> Warn against the use of .unwrap() and .expect() unless accompanied by
> a '// PANIC:' comment. This enforces safety standards in the Rust-
> for-Linux project until upstream Clippy lints are integrated.
>
> Suggested-by: Joe Perches <joe@...ches.com>
> Suggested-by: Miguel Ojeda <ojeda@...nel.org>
> Link: https://github.com/Rust-for-linux/linux/issues/1191
> Signed-off-by: Jason Hall <jason.kei.hall@...il.com>
Ideally, this would be two patches -- one performing the move and the
other adding the new lint.
Either way, the file should be added to `MAINTAINERS` -- not sure if
Joe would want to maintain it or perhaps have a new sub-entry or
perhaps a co-maintainer etc.
> + "Avoid unwrap() or expect() in Rust code; use proper error handling (Result) or justify with a '// PANIC: ...' comment.\n" . $herecurr);
By "proper error handling", I guess you mean bubbling the error up
with `?` or similar, right?
There are also other options, like using `unsafe` sometimes etc.
I think perhaps the best is to keep the message a bit less strict
(since there are cases where it is OK) and put the details in a link
to, say, https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
(Cc'ing Dirk who was involved in that).
I am thinking of something like:
`unwrap()` and `expect()` should generally be avoided in Rust
kernel code modulo some exceptions (e.g. within asserts in doctests).
If the use is intended, then please justify it with a `// PANIC:`
comment. Please see ...
But I will let others comment...
(Also, please Cc all the maintainers/reviews of Rust and checkpatch --
doing so here).
Thanks!
Cheers,
Miguel
Powered by blists - more mailing lists