From nobody Sat Feb 7 08:27:50 2026 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 1B00E36654D for ; Mon, 2 Feb 2026 13:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770040569; cv=none; b=gmtOOqN7MPM6Anu9iDDoiM9gviAefjvJMZcqEOUwFZRr+3BE3g1Kdqb4M981oUXHp07qkNN92hXws0Xo4SteH1z2pCRLbzV+GLWkoV8VCrNwVbDmWHTpQCqbEGDt6qyN+T57brh4X5r34fneeOH4OHBla8uxC6XcRacGjYGeJ8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770040569; c=relaxed/simple; bh=I3hdn0is2B4hFR7yLjTdMqo1s5U6WpPHWCgDsrJ45Ww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KhPbbIAtWe/hFGn7bc3vmKIoqpbyppHTYsUmxFByaz4UB+6D+eDNLaWqDA9xIWxJRIw0YtlHAX41bZSXjN8uNlcUWhR/zfi89yifGw1B7ekphlsSaHNTbeiAceDFg/js54xooPOhADU/cIwWSfMscflIUQHPddGPUIfLJpvATlQ= 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=DJDCR7JZ; arc=none smtp.client-ip=74.125.82.176 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="DJDCR7JZ" Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-2b71557299dso4519722eec.1 for ; Mon, 02 Feb 2026 05:56:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770040567; x=1770645367; 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=4szHbuFxqmXA3vP2xDtj9lQOqQZM7yRsk7nkYjSTgFc=; b=DJDCR7JZOwmfHQpgS0YLUzotns4Z90sOQs+l6vwsHmu2EnsiLVn+K1NhaWMlqhJZHZ gQYMAD9Xqt58VfDUY90ws4ZGNNCinpk6+tEm2vwKHyR6HA3/+CGr0E8sP9/CslQ24Zz6 vBfAwMthU7sSflCkl4CS1h36jY/u5r9L7/wD08zEDYeS/DScrvs1omD1vCPLua2JqHKW nW/VAu/K2t8zUiJl+owwTPXGjEevfEs/XgVxOp7bhTN0GxytuhCDxj61DJp/vlqbAoyo 0ZoXeJctbnqeD/fTWxrxwNOs+lHx5KwLOwQy4mLMWn1oOzjFlzArvsl5vlRTzwwIszNc ZOCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770040567; x=1770645367; 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=4szHbuFxqmXA3vP2xDtj9lQOqQZM7yRsk7nkYjSTgFc=; b=IleXXawrZxz0Ev3jQRZQfDyFWoUXhXczNLPiGRh5Sm7YXlEfBO6/eRPDU/hpaRSsNT CDHCukS2PUibiNJ6HSKHBNWV0xEHlCr/d3k88SyYHhzRs4h2JPLoHjcaV3lbqDrIHncc 7I6mI0WvRqzJITbR51Je0uP0pUOY837bOl6TeOVO9U4wwv73ikxUxMTZzBNSIaPirXnT vlMUDhXQgevj2YDKdNe8MdSacXhMFgIYBYcTmmUvHhe8QorNRGQQfUKOkUXOwMcJ4wBD QWozoKdBuaUavhK3Js64agRwY2LXu1Z5mRk42qlWC391HVH24LxhLL5sZlVP8hFWNcGw wvnQ== X-Forwarded-Encrypted: i=1; AJvYcCUaouVe7rREUfBB4xaDZdOP6OlQ/yP4WI9ipwUfQ7rq4F9+4WG9pYy7bzlhYFaYtItrHBEk9gtRaQPWDU0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw87/vyNcalte3bceIVcv+vQhW53mfS7db63AY2J32gB3zNUvVL tjdFxx+PmxkC/KLExPYrXSaj6mhQso/YuyyWZ0NBhywEwlIIaGcrxcff X-Gm-Gg: AZuq6aIv4YP+0m6vaDVkU+7ZQ/83oVF4laFetCBLut1lk1PqL775KEmi2sYiqqTLe+l aYvMgm4o13doT1o8dBlQa42eoVyz4A/wOR5c4bHS6VlNvxmBNoOTC0DxdzA0Eztf68gRo8izjlH 7M698QIePa0yOsYUxFUsF91jwVCy53MPlHFECbBycpj6piSxXCmrpGL5tgqgHgDS4ZqV1h3g4Zl VY0EUMaYRJNVC4xBhHSAIvcLoj6IG2Oz8psVgOM8/TW9sq/7o3KaE7j7hQfvJ9dxJ4e/2ciwRx0 Wb/seW01zccSyTfFNFuPxUlXEBkAk3f785kG+G9PMUYbOYYIytNllONU9pjDHq2hkUO1cMYQ9k4 hgKuHoFNwiCl0zVF1TJ5Ey1S0GJ3zZhpdmYIpHxV/HB4oBtW0RQRIs29n06HbxI9UCUJu+z4I5C PBTD6PTUBRKBPCE4LWeu7H0nU20t1r/a1J8fA2k5N8wwE6b/9WDRh2tg0BByf+hA== X-Received: by 2002:a05:7300:8ca0:b0:2b6:aa89:4b59 with SMTP id 5a478bee46e88-2b7c892cbb8mr5770852eec.36.1770040566836; Mon, 02 Feb 2026 05:56:06 -0800 (PST) Received: from jason-hall-A520-B.. ([2600:8800:41a0:8000:4339:af89:9643:898]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b7a16cfa25sm20061490eec.5.2026.02.02.05.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 05:56:06 -0800 (PST) From: Jason Hall To: Joe Perches Cc: Dirk Behme , Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Hall Subject: [PATCH v4] scripts: checkpatch: warn on Rust panicking methods Date: Mon, 2 Feb 2026 06:56:02 -0700 Message-ID: <20260202135602.1886134-1-jason.kei.hall@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <14d95956-05dd-4c9b-b748-894c1d474c1c@de.bosch.com> References: <14d95956-05dd-4c9b-b748-894c1d474c1c@de.bosch.com> 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" 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 Link: https://github.com/Rust-for-linux/linux/issues/1191 Signed-off-by: Jason Hall --- 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. 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)$/); =20 +# check for Rust unwrap/expect + if ($realfile =3D~ /\.rs$/ && $line =3D~ /^\+/) { + if ($line =3D~ /(?:\.|::)(?: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 !=3D $checklicenseline && $rawline =3D~ /\bSPDX-License-Identifier:/ && --=20 2.43.0