From: Dirk Behme <dirk.behme@de.bosch.com>
To: Jason Hall <jason.kei.hall@gmail.com>, Joe Perches <joe@perches.com>
Cc: Miguel Ojeda <ojeda@kernel.org>, <rust-for-linux@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4] scripts: checkpatch: warn on Rust panicking methods
Date: Tue, 3 Feb 2026 07:21:34 +0100 [thread overview]
Message-ID: <288d4aeb-af0d-4d50-bb0d-7a046abaaf10@de.bosch.com> (raw)
In-Reply-To: <20260202135602.1886134-1-jason.kei.hall@gmail.com>
Hi Jason,
On 02/02/2026 14:56, Jason Hall wrote:
> Add regex check in checkpatch.pl for common Rust panicking methods
> like unwrap() and expect().
>
> Allow an exception if the line contains a '// PANIC:' comment.
>
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Link: https://github.com/Rust-for-linux/linux/issues/1191
> Signed-off-by: Jason Hall <jason.kei.hall@gmail.com>
> ---
> Hi Dirk,
>
> Now using imperative mood. I decided to keep that logic stateless
> unless its agreed that we need to add state. Adding checks for #[test]
> and other test identifiers will make this much more complicated. There
> is already a check for // PANIC: that works fine.
Yes. I'm just slightly unclear what we do with existing code where using
`unwrap()` is fine/accepted/required? And with patches like
https://lore.kernel.org/rust-for-linux/20260131154016.270385-3-shivamklr@cock.li/
I would guess with this change we would get warnings on that?
So the idea is that we would need some add-on patches on top of this to
annotate existing code / patches with `// PANIC: ...` to stay warning clean?
Thanks,
Dirk
Btw, what's with Gary's comment to drop `expect()`?
> v4:
> - Use imperative mood in commit description.
> - Fix patch formatting and placement of '---' separator.
> v3:
> - Use non-capturing groups (?:) to optimize regex.
> v2:
> - Switch from \b to (\.|::) to avoid false positives in strings.
> - Add : to PANIC comment check.
>
> scripts/checkpatch.pl | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index c0250244cf7a..37bdf602e7e7 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3834,6 +3834,17 @@ sub process {
> # check we are in a valid source file if not then ignore this hunk
> next if ($realfile !~ /\.(h|c|rs|s|S|sh|dtsi|dts)$/);
>
> +# check for Rust unwrap/expect
> + if ($realfile =~ /\.rs$/ && $line =~ /^\+/) {
> + if ($line =~ /(?:\.|::)(?:unwrap|expect)\s*\(/ &&
> + $rawline !~ /\/\/\s*PANIC:/ &&
> + $line !~ /^\+\s*\/\// &&
> + $line !~ /^\+\s*assert/) {
> + WARN("RUST_UNWRAP",
> + "Avoid unwrap() or expect() in Rust code; use proper error handling (Result) or justify with a '// PANIC: ...' comment.\n" . $herecurr);
> + }
> + }
> +
> # check for using SPDX-License-Identifier on the wrong line number
> if ($realline != $checklicenseline &&
> $rawline =~ /\bSPDX-License-Identifier:/ &&
next prev parent reply other threads:[~2026-02-03 6:21 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-01 15:57 [PATCH] " Jason Hall
2026-02-01 17:19 ` Charalampos Mitrodimas
2026-02-01 18:30 ` [PATCH v2] " Jason Hall
2026-02-01 19:37 ` Joe Perches
2026-02-01 19:57 ` [PATCH v3] " Jason Hall
2026-02-02 5:38 ` Dirk Behme
2026-02-02 13:56 ` [PATCH v4] " Jason Hall
2026-02-03 6:21 ` Dirk Behme [this message]
2026-02-03 15:25 ` Jkhall81
2026-02-03 15:49 ` Onur Özkan
2026-02-03 16:02 ` Gary Guo
2026-02-03 16:32 ` Onur Özkan
2026-02-03 16:54 ` Gary Guo
2026-02-04 15:56 ` Dirk Behme
2026-02-04 18:10 ` Miguel Ojeda
2026-02-04 19:08 ` Joe Perches
2026-02-05 1:42 ` [PATCH v5] scripts: checkpatch: move Rust-specific lints to separate file Jason Hall
2026-02-05 20:55 ` Miguel Ojeda
2026-02-06 8:31 ` Dirk Behme
2026-02-06 17:41 ` Miguel Ojeda
2026-02-07 15:56 ` [PATCH v6] " Jason Hall
2026-02-07 16:07 ` Miguel Ojeda
2026-02-07 16:53 ` [PATCH v7] " Jason Hall
2026-02-07 18:46 ` Miguel Ojeda
2026-02-07 21:07 ` [PATCH v8 0/2] modularize Rust lints and add RUST_UNWRAP check Jason Hall
2026-02-07 21:07 ` [PATCH v8 1/2] scripts: checkpatch: move Rust-specific lints to separate file Jason Hall
2026-02-07 21:53 ` Miguel Ojeda
2026-02-07 22:49 ` [PATCH v9 0/2] modularize Rust lints and add RUST_UNWRAP check Jason Hall
2026-02-07 22:49 ` [PATCH v9 1/2] scripts: checkpatch: move Rust-specific lints to separate file Jason Hall
2026-02-07 22:49 ` [PATCH v9 2/2] scripts: checkpatch: add RUST_UNWRAP lint Jason Hall
2026-02-08 7:55 ` Dirk Behme
2026-02-08 14:01 ` Jason Hall
2026-02-09 8:52 ` Dirk Behme
2026-02-08 6:43 ` [PATCH v9 0/2] modularize Rust lints and add RUST_UNWRAP check Greg KH
2026-02-14 6:11 ` Dirk Behme
2026-02-14 23:30 ` Miguel Ojeda
2026-02-14 23:32 ` Miguel Ojeda
2026-02-07 21:07 ` [PATCH v8 2/2] scripts: checkpatch: add RUST_UNWRAP lint Jason Hall
2026-02-05 13:23 ` [PATCH v4] scripts: checkpatch: warn on Rust panicking methods Dirk Behme
2026-02-05 21:00 ` Miguel Ojeda
2026-02-04 18:11 ` Miguel Ojeda
2026-02-01 19:51 ` [PATCH] " Gary Guo
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=288d4aeb-af0d-4d50-bb0d-7a046abaaf10@de.bosch.com \
--to=dirk.behme@de.bosch.com \
--cc=jason.kei.hall@gmail.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/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
all inboxes | Powered by JetHome®