[PATCH v6] scripts: checkpatch: move Rust-specific lints to separate file

Jason Hall posted 1 patch an hour ago
There is a newer version of this series
MAINTAINERS                |  6 ++++++
scripts/rust_checkpatch.pl | 15 +++------------
2 files changed, 9 insertions(+), 12 deletions(-)
[PATCH v6] scripts: checkpatch: move Rust-specific lints to separate file
Posted by Jason Hall an hour ago
Create scripts/rust_checkpatch.pl for Rust-specific linting logic.
Add a conditional loading hook in scripts/checkpatch.pl to call it.
This will allow Rust linting logic to be maintained independently.

Add a new entry to the MAINTAINERS file to track this new file.

Suggested-by: Joe Perches <joe@perches.com>
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>

---
---
 MAINTAINERS                |  6 ++++++
 scripts/rust_checkpatch.pl | 15 +++------------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2c0bdd08b74c..57831dc30e6b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5880,6 +5880,12 @@ R:	Lukas Bulwahn <lukas.bulwahn@gmail.com>
 S:	Maintained
 F:	scripts/checkpatch.pl
 
+CHECKPATCH RUST LINTS
+M:	Jason Hall <jason.kei.hall@gmail.com>
+L:	rust-for-linux@vger.kernel.org
+S:	Maintained
+F:	scripts/rust_checkpatch.pl
+
 CHECKPATCH DOCUMENTATION
 M:	Dwaipayan Ray <dwaipayanray1@gmail.com>
 M:	Lukas Bulwahn <lukas.bulwahn@gmail.com>
diff --git a/scripts/rust_checkpatch.pl b/scripts/rust_checkpatch.pl
index 69db5ded7371..56c1bc29d3f2 100644
--- a/scripts/rust_checkpatch.pl
+++ b/scripts/rust_checkpatch.pl
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 # SPDX-License-Identifier: GPL-2.0
 #
-# (c) 2026, Jason K. Hall <jason.kei.hall@gmail.com>
+# (c) 2026, Jason Hall <jason.kei.hall@gmail.com>
 
 use strict;
 use warnings;
@@ -9,17 +9,8 @@ use warnings;
 sub process_rust {
     my ($line, $rawline, $herecurr) = @_;
 
-    # check for Rust unwrap/expect
-    if ($line =~ /^\+/) {
-        if ($line =~ /(?:\.|::)(?:unwrap|expect)\s*\(/ &&
-            $rawline !~ /\/\/\s*PANIC:/ &&
-            $line !~ /^\+\s*\/\// &&
-            $line !~ /^\+\s*assert/) {
-            return ("RUST_UNWRAP",
-                    "Avoid unwrap() or expect() in Rust code; use proper error handling (Result) or justify with a '// PANIC: ...' comment.\n" . $herecurr);
-        }
-    }
+    # Reserve for future Rust-specific lints
     return ();
 }
 
-1;
\ No newline at end of file
+1;
-- 
2.43.0
Re: [PATCH v6] scripts: checkpatch: move Rust-specific lints to separate file
Posted by Miguel Ojeda an hour ago
On Sat, Feb 7, 2026 at 4:56 PM Jason Hall <jason.kei.hall@gmail.com> wrote:
>
> Link: https://github.com/Rust-for-linux/linux/issues/1191

I guess the link doesn't hurt, but the link is a bit tangential for
this patch (unlike the other one, of course).

> -# (c) 2026, Jason K. Hall <jason.kei.hall@gmail.com>
> +# (c) 2026, Jason Hall <jason.kei.hall@gmail.com>

Unrelated change?

> -    # check for Rust unwrap/expect
> -    if ($line =~ /^\+/) {
> -        if ($line =~ /(?:\.|::)(?:unwrap|expect)\s*\(/ &&
> -            $rawline !~ /\/\/\s*PANIC:/ &&
> -            $line !~ /^\+\s*\/\// &&
> -            $line !~ /^\+\s*assert/) {
> -            return ("RUST_UNWRAP",
> -                    "Avoid unwrap() or expect() in Rust code; use proper error handling (Result) or justify with a '// PANIC: ...' comment.\n" . $herecurr);
> -        }
> -    }

This diff seems to be based on the previous patches. Each version of a
series should be a rebase, not a stack.

Thanks!

Cheers,
Miguel
[PATCH v7] scripts: checkpatch: move Rust-specific lints to separate file
Posted by Jason Hall 49 minutes ago
Create scripts/rust_checkpatch.pl for Rust-specific linting logic.
Add a conditional loading hook in scripts/checkpatch.pl to call it.
This will allow Rust linting logic to be maintained independently.

Add a new entry to the MAINTAINERS file to track this new file.

Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Jason Hall <jason.kei.hall@gmail.com>

---
---
 MAINTAINERS                |  6 ++++++
 scripts/checkpatch.pl      | 14 ++++++++++++++
 scripts/rust_checkpatch.pl | 16 ++++++++++++++++
 3 files changed, 36 insertions(+)
 create mode 100644 scripts/rust_checkpatch.pl

diff --git a/MAINTAINERS b/MAINTAINERS
index 2c0bdd08b74c..57831dc30e6b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5880,6 +5880,12 @@ R:	Lukas Bulwahn <lukas.bulwahn@gmail.com>
 S:	Maintained
 F:	scripts/checkpatch.pl
 
+CHECKPATCH RUST LINTS
+M:	Jason Hall <jason.kei.hall@gmail.com>
+L:	rust-for-linux@vger.kernel.org
+S:	Maintained
+F:	scripts/rust_checkpatch.pl
+
 CHECKPATCH DOCUMENTATION
 M:	Dwaipayan Ray <dwaipayanray1@gmail.com>
 M:	Lukas Bulwahn <lukas.bulwahn@gmail.com>
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c0250244cf7a..f75cb70ad0dd 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -20,6 +20,12 @@ my $D = dirname(abs_path($P));
 
 my $V = '0.32';
 
+my $rust_checkpatch_available = 0;
+if (-e "$D/rust_checkpatch.pl") {
+	require "$D/rust_checkpatch.pl";
+	$rust_checkpatch_available = 1;
+}
+
 use Getopt::Long qw(:config no_auto_abbrev);
 
 my $quiet = 0;
@@ -2947,6 +2953,14 @@ sub process {
 
 		$cnt_lines++ if ($realcnt != 0);
 
+# Check for Rust-specific lints
+		if ($rust_checkpatch_available && $realfile =~ /\.rs$/) {
+			my ($type, $msg) = process_rust($line, $rawline, $herecurr);
+			if ($type) {
+				WARN($type, $msg);
+			}
+		}
+
 # Verify the existence of a commit log if appropriate
 # 2 is used because a $signature is counted in $commit_log_lines
 		if ($in_commit_log) {
diff --git a/scripts/rust_checkpatch.pl b/scripts/rust_checkpatch.pl
new file mode 100644
index 000000000000..56c1bc29d3f2
--- /dev/null
+++ b/scripts/rust_checkpatch.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+# SPDX-License-Identifier: GPL-2.0
+#
+# (c) 2026, Jason Hall <jason.kei.hall@gmail.com>
+
+use strict;
+use warnings;
+
+sub process_rust {
+    my ($line, $rawline, $herecurr) = @_;
+
+    # Reserve for future Rust-specific lints
+    return ();
+}
+
+1;
-- 
2.43.0