From nobody Sat Feb 7 07:24:41 2026 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FA501C862D for ; Thu, 5 Feb 2026 01:42:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770255743; cv=none; b=cNv8J35cB2IcQPN8T/2g+Yu3L9iHjfh8KNfWUPJhh/gW87BBJmXUEAcNXGi//FhdY2h7A34tB6PR1VVUOGnYW42TuYO8z8WNcaVCh9Py8+ul2lb8DLlnbS7qfVLBlsFME7ewbgHEockIRMBqScnKkiqwIFr2EK/1Tp45+fPOg+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770255743; c=relaxed/simple; bh=gn10Y6NPKsCmNVsWCFH/QBmf5hMYk7Hi3FCUJAjJ12U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ONRgfJ0hAukxgiX/l7nHHtv/snaWEIeCODQHtUassYXdaXvCv733K53EiVNwEz0CU3sl2krl1ZX9wVTLVt2meEq7CZCNleRdf0+COQeiM3YXCqh6XHfdQba5DJR7tv5ntpJQ/z7NvGfHmfiqkSL7JWlH8aHsErpjT+ISr8lR+z0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m9iVNaCF; arc=none smtp.client-ip=74.125.82.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m9iVNaCF" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-124a95e592fso1494361c88.0 for ; Wed, 04 Feb 2026 17:42:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770255743; x=1770860543; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fC9JdQupaFL0bYrlsOyosUwyhZcdzFHaPEvPFp+Yb/U=; b=m9iVNaCF4k5sHMJBc9ibSLfRKZTUZXg4IDzQamIILrY1OrswCpWgUOWosLapnqjiLb sv+2rKk5pRzMXSb8GMAXpx8iijeImvqIYtLLm3iS8hl6Jejs8C4ueteCJEpFeoP1ItCJ VkAzKYW8lMq0KbsT5/L75ph7zhIP+BPh74IymWlVqWyiD2lw8gMzF3xyBzWhHhmYgWL6 MsHvvu0lzrm4vRKhnEv1rB7RGOGJmQle4d+4r42IlU6a6ztwDw34VSgehnGLt/OCT3cZ v9EafyanmFua0ez1H8JmijfbulT+cCNP2p0XWVlSmI1O0+h8cN6quEZY2llqJBS72UAb U1gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770255743; x=1770860543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fC9JdQupaFL0bYrlsOyosUwyhZcdzFHaPEvPFp+Yb/U=; b=dH9wLS28Hyw9luQgOUCXrFqujMtHJC9VmWpzbKAcfchbrRJHAuJkCnBgXtyXbTAWkS sVw+42hCSkq1USdmmlCRdj/FAsY+tWIrZwtTuiyyeDIghCzpDbBjcDOkEVvV6ya+I5nu tHM4lgLZsp31rDXvmzIr2XDmotOmA0YYn+WF6woWqx7iERB6nLoS5ZqXCRLJTjl1DcS/ WcAWACl/rly5zJSblHMO9MRDUjPDCswRT49r64nJ1oLCfe5+7DJkohvOhzQ+FrI0wDaD h24snSEO9n6asLGTQSKGD7Jl+BQanXhgfwWQNKW8JJ6CneE+lot3ci+R0ijEZk+trzcT VbEQ== X-Forwarded-Encrypted: i=1; AJvYcCXRYOlGHLX3GH/TFnxIGmZwSrp+T0wQc8uvB6TffKUBEq/b57G71OaZ/lFg2/2Mss+scFOnZYvpKw4obyE=@vger.kernel.org X-Gm-Message-State: AOJu0YykwdYLRNym6qThAYT57E6x3tAdd2s74I62bGv2CeyniXz06s0D ARY1G3au+8//4vhBo/cACnJw7llvZo7T0fO4lcZzcMxOkxQ5hcYAxvIu X-Gm-Gg: AZuq6aIRIWXMrRnUN/6i0RfIflWDYlCuUqfkdiuM3pFDQHGRD+kTaX2hLWqm063Q6SV Y0BInNeTHA++REqZrG8ZhVBSSdcluZQq04dc1A8Blm+jS1Y92s/a+fuIGzxhgwZMXgM0w/u1hI5 Lxp82wAq9GbzHqrRtELap9A9czMIHNW82yt0NzgfGP9rn8ymI7b+XVZ541ArnyKK3l9VlL+h8P8 GuC16Gms8jqQnCbn5OX2QM2jmV0/R26eyOFEUelebUPWDHi7CtzilaAIEDCWbo6DZeHZLn6rWYK KFuXhJp3gOnASURv7BrOntIV745uUFKnScxZbb0GORva2kPqzpq7NH5u90P9NGtZABPKZXUgs3C GNwRM/K3nrjK+HdVqU5zwXrYw0Ak4CUOMEFURSRzHoApBLvPiCRD5RIqOqLxJ4xwW7clT2oYBB6 lX2S4mpP2x+PyrwAsPzjXEn1q6wDsKQ84POv93OGPieFFtZbCJzr7ZuR+xYH9aLvE= X-Received: by 2002:a05:7022:f103:b0:123:345f:5d9c with SMTP id a92af1059eb24-126f47720f4mr2264866c88.2.1770255742414; Wed, 04 Feb 2026 17:42:22 -0800 (PST) Received: from jason-hall-A520-B.. ([2600:8800:41a0:8000:ede3:2250:7779:19b7]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-126f4bb8b02sm3377242c88.0.2026.02.04.17.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 17:42:21 -0800 (PST) From: Jason Hall To: Joe Perches , Miguel Ojeda Cc: Dirk Behme , Gary Guo , =?UTF-8?q?Onur=20=C3=96zkan?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Hall Subject: [PATCH v5] scripts: checkpatch: move Rust-specific lints to separate file Date: Wed, 4 Feb 2026 18:42:18 -0700 Message-ID: <20260205014218.2202385-1-jason.kei.hall@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Suggested-by: Miguel Ojeda Link: https://github.com/Rust-for-linux/linux/issues/1191 Signed-off-by: Jason Hall --- v5: - Move Rust-specific logic to scripts/rust_checkpatch.pl (Suggested by Joe= Perches). - Add conditional loading hook in scripts/checkpatch.pl. - Updated regex to use house-style comments. 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 | 14 ++++++++++++++ scripts/rust_checkpatch.pl | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 scripts/rust_checkpatch.pl 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 =3D dirname(abs_path($P)); =20 my $V =3D '0.32'; =20 +my $rust_checkpatch_available =3D 0; +if (-e "$D/rust_checkpatch.pl") { + require "$D/rust_checkpatch.pl"; + $rust_checkpatch_available =3D 1; +} + use Getopt::Long qw(:config no_auto_abbrev); =20 my $quiet =3D 0; @@ -2947,6 +2953,14 @@ sub process { =20 $cnt_lines++ if ($realcnt !=3D 0); =20 +# Check for Rust-specific lints + if ($rust_checkpatch_available && $realfile =3D~ /\.rs$/) { + my ($type, $msg) =3D 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..69db5ded7371 --- /dev/null +++ b/scripts/rust_checkpatch.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 +# +# (c) 2026, Jason K. Hall + +use strict; +use warnings; + +sub process_rust { + my ($line, $rawline, $herecurr) =3D @_; + + # check for Rust unwrap/expect + if ($line =3D~ /^\+/) { + if ($line =3D~ /(?:\.|::)(?:unwrap|expect)\s*\(/ && + $rawline !~ /\/\/\s*PANIC:/ && + $line !~ /^\+\s*\/\// && + $line !~ /^\+\s*assert/) { + return ("RUST_UNWRAP", + "Avoid unwrap() or expect() in Rust code; use proper e= rror handling (Result) or justify with a '// PANIC: ...' comment.\n" . $her= ecurr); + } + } + return (); +} + +1; \ No newline at end of file --=20 2.43.0