From nobody Sat Feb 7 08:22:58 2026 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (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 E596B1A5B84 for ; Sun, 1 Feb 2026 20:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769976103; cv=none; b=nrJq8mUmptAX4zsZaOlUulli2lLI1aO0QsxPkOAd9Whg7My1favh/W07FCbr/Yi/D2AxNCGEp8W3nJlU0tzLC4p48ZvA5tlJK1rjqlq0HrYykLlEPGUPC0mEipilLWGkBYqCWqAoh5U+CfAnCtR+xxTzVDjiahUWG/+BedNDcvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769976103; c=relaxed/simple; bh=ETc2WuUnn56+VKanb2VtkP/p3TRPNBAC+8RgtWoYcZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F1/UceFnniPrKn8f1tNTUWY1djrQJrAYIdNlbFLVCeOJnUf+q9tHCchhFgbPYuDb4vgzX40871sq/HBfMrTImDmyCduqs42DyhzcSj7fbBX+0kx50xDJ87EDlEl69BBbDNSL3Sw/EmLkBy53FvT6lBbXZhxQ3AAwFQyuRQa39BY= 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=OR8ARAyw; arc=none smtp.client-ip=74.125.82.45 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="OR8ARAyw" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-124afd03fd1so5535325c88.0 for ; Sun, 01 Feb 2026 12:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769976101; x=1770580901; 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=IjOcUjW0L3Es4us2PLQLz4GAhrL5zk2fsCTd8Kf8Rf8=; b=OR8ARAywjbsZ7LcIL9LgBdwOLMBpJDossDuS/zm85rlUFvuWOHTIpHcw9T/cR3rm9S u7tPV14VbbOvNRCM9zmZ59U48PROmpOBBTw6u4wyoyXwYEYhdD3ujcRTt4+sEzfMUoJK OxW1PDAEsKuKnKJYIHfUffZxDylL1/Jh1ZbDMkq40Ea+aaXG+oUyP2hRfOAQAbEhB2IR ZnC5Ac9mWptmpf1l+xcZ/uQuKZmxLu8Y8Ups3VzbWmQrWiJG37RzYxtx88cth0X7bC0Y t0D7ERus0+Amtp/xLSpitrSs0TRifOt83OmeLQxkRfHJXQElsnx0LQPqoey569y6yUNI 7a1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769976101; x=1770580901; 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=IjOcUjW0L3Es4us2PLQLz4GAhrL5zk2fsCTd8Kf8Rf8=; b=YXAfFyK3Y2H5QP0GiSe+1IMbi5bSh8I1/m7K4b0uT9FKsZaDXXwW65k1nPdNrqCT7O dOX/hewqQnrqzzZrs1PYkkeNyUubqtGxxayZgYDWOSs+QnYypVbHBJEKPP6AhS/BMDys eIzKvA9/+l2KfdZZzaUDKa9Y2yYk6eye4IF5d0Awn521og2v4skxI+snZ2dzOZj8QRvi etZ7XVk+8NmgbIT5HGDCYW1kaLP+6/RkKh6parYJBUJ42QCsdI93h9wFu7zjJNnfFeVM CgXG3Ig0Hx5D7UzpVnmNbRpDKJOhp3N+kYPLEw3SUtoJFNO3o5mHjlQrKMfoi7ujCclv o8lw== X-Forwarded-Encrypted: i=1; AJvYcCXyBfpElcmkFoGX8xYCegg4qSfvQox29rkRPowwz+zznCCxlF9OR2jvYnG5tKykOci4p1EhROdpt5lJWhc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2DFfHPGtbHamUI68H847gVM2n8oJEHeBdi20VyQTasysVbvPS ucwmIkh8+s3ZtCJJEhQ3rfM2pDkZ/yv0MOb78DqZmRzHcoNDrX0nwMCC X-Gm-Gg: AZuq6aJgr9ik7IeVUc3bRPnRDSfykqmOeQogMGhtGJVS9Pi2E2mD8mu1h1qg+SuYEZd xylGfQt+3caolAyC0Vevg2u/JY29f1EITWsI4XJ4QTiIQ3h8rtVgMNfA2K9myJBvOmfRwpdTsUx q48n3ubFA6nQgmZ0CZk0azNfdXeekPEZiWqFBbgR22IyvovEaNNSrVMQLGbzLU5a0Dk9mO4ejut rfZ9oyVofJEO1SrXq3uhNqJDYmFLdapmVWfrmDJ8YiHMqOeEAbIvE5qt0wETE3fVjm7DNdportW CT2nDWNfl6RQgKQfr3JxebDjcK6l7P/w1luhvS1wswjZYQ4bEtFJe6kWR//PUHaO3DlrpQJcRrP 4IzRMRBdCR5ImPxb8mis+eFzkAK5JcevdvoLKoJI8Y/JjE8evg1mnoZO5BVa1OjJrhYEAL8pFWa g7uqraFvMUefFyAbNI6cmh4eiHUrYmXPzXtX53i1Rv6ORNGN/sTolqw5HluzT9z4I= X-Received: by 2002:a05:7022:e1e:b0:11b:923d:773f with SMTP id a92af1059eb24-125c0f7da99mr3798108c88.5.1769976100910; Sun, 01 Feb 2026 12:01:40 -0800 (PST) Received: from jason-hall-A520-B.. ([2600:8800:41a0:8000:38f6:2506:345b:4004]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9d7f95asm16115252c88.7.2026.02.01.12.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Feb 2026 12:01:39 -0800 (PST) From: Jason Hall To: joe@perches.com Cc: charmitro@posteo.net, foster.ryan.r@gmail.com, ojeda@kernel.org, gary@garyguo.net, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Hall Subject: [PATCH v3] scripts: checkpatch: warn on Rust panicking methods Date: Sun, 1 Feb 2026 12:57:38 -0700 Message-ID: <20260201195737.1715632-2-jason.kei.hall@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <875x8gqt3y.fsf@posteo.net> References: <875x8gqt3y.fsf@posteo.net> 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" Added regex check in checkpatch.pl for common Rust panicking methods like unwrap() and expect(). Allowed 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, Joe, I updated the regex, and I looked at Ryan Foster's patch. These two PANIC checks don't seem to interfere with each other as far as I can see. --- v3: - Using non-capturing groups (?:) to optimize regex. v2: - Switched from \b to (\.|::) to avoid false positives in strings. - Added : 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