From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) (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 A093233890B for ; Sun, 8 Feb 2026 07:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.66 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770537346; cv=none; b=PCUFuPrc/3/M06Ms835g5PAF9VbPweO3nsWS6FMP7r1Q+3elkS2YMRUtov9Fe4sYwd13sQrynxNmlXUhWMPww0LYod0SRlxn1wjU5l+g0QTLjPXDtarJY++4Q6w//vbUdh1Hf9duDwDGOTlCAxyk8B9gL2TCInArgIyX2XncfLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770537346; c=relaxed/simple; bh=3a9QhNIrYqhvijosCbQ+6UHxLzZsM2aXEyEwX22+Ibc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=e2WyqoUz3dXTf9nO++Cl36ycMajB375xhUSZbj1KP3Uqd12QPWB9gVLB+EcMn0JwLLsD1yx2TVSviQgZ1XFfGwuvhU/jaWbkQvyHY6VhIWZuG/xfNFTlGwPPbNZwJvksJowUE9QS+DWQGltG2IY5IQZonfz1Uuq6oC6yycSc/kU= 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=NgMdadyv; arc=none smtp.client-ip=209.85.128.66 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="NgMdadyv" Received: by mail-wm1-f66.google.com with SMTP id 5b1f17b1804b1-4801eb2c0a5so32167665e9.3 for ; Sat, 07 Feb 2026 23:55:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770537344; x=1771142144; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CILrPNxeMzqYF9DydhPhafI3xHuSld0NaekSWF+cSMw=; b=NgMdadyvVaqNHoacZWQ/uTzOcP46ca0wBL/K/RD1RL1JD/aFvoejZZSgnOfBfXbRzk hlQxuynIOKCcx08Yxfklsa8JDtA1BwfaQmdnep4c+t4OUl7zaZOas4kl+stJ8f+z1Cfc o6ZTSDPcqT8i/TIVgSJ8yN+ejeWwy6PilJo+XuGRAuM92owyq69RS5ybIAOiPYv1XAvA uG2FzT98JBGxUDr04VCg4+NsgWeNay0b+80q/L59ToQf0I+8DYwggW0BjkpOZhoiSJlI 2CB/cn4A05HFj3MhvilmBJwAs0vA3MREOguh5Pylumkj3WvJoqkb3oCQkDpOLas4GzQj tbag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770537344; x=1771142144; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CILrPNxeMzqYF9DydhPhafI3xHuSld0NaekSWF+cSMw=; b=RrjxpvIbFsB8i5fQBD52aZ3GEhFUmJgxcdVxf47DJB3aBzgmqpvVrTLNzW/HQpWobN UoFDIiDczJaBdSJGl3UKGrz7ehtRzd/UBJd03JCVFBUxyaHziK1lT5WphNUIBzATmuV3 RQt1WV110qtj6A9qOnWUwzouIr+opG6TUmIA7wiDROiNp3iy15T4KfiloWnLr5BDlTYy ih2CI41h65Radehn2X/mSJgN2T4VjyxS4lHALUoFk6dgY2HLl4l4m/vTsJSW41QB3oFz Ui4qo537Fh8klV9Cfx2000CDkBGDacOWYdwWrDGET4M3yBAsfxg90RcxQwUQa1Hqd6CZ SDGQ== X-Forwarded-Encrypted: i=1; AJvYcCUJAEDqRxh0Qn/a+Hc2kT1qNYCT3fmXg45gD/wHfkdqdiTxFLPKIQAuRlM5601brFOj42z2/pwy0ljxM3w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7dHDW6vpwGG+tMiJRrx5uOTxBlauqL2B0k+TuFcYBY6a+P0c4 bBBzEm0M1beahj8k4D/QccQJuOEpIv+lhbOcLRHzPkSd3VTG3JAsMW8V X-Gm-Gg: AZuq6aIu5hRZqiabp26vHNBWlS/JX1s7+VMq15JK/ys2cJbKKNW2aUQFhcanCMklOnE KYYoT6mXNTBTmzgF9lr1X9FTyVeUeknBbDAbqHo0xhCZoL2PbLwNx6sWpOe89JT7gXhDm7D4Txl R+Wi1H5iOQXs1GHv4xYh/HEHSTK2FoKMHgnOYtzzfmkOpWqKm04PDoi0HwKymA0MyJ/rYAm4+ru k6nJO/r0btGGTHStoePvN+FPj4orVYZbItVvoeuRZtVouZhYf1A6Ae8qGL8IPKmdE4Xy/iKGlQW iFxYFwfmzBNlCQGwm9LkeO+1TYL8wz47MqwG+kRa1DLTmXihe7YjUjJjSdzlm5vcDBLPfka77gM H7erMRfhg8RwnoGBhK2VDXZV80WulNbumFA3TV/lV2EIal3Lix+G74qfBb1Mi8Wz9G/b6NO/rqu qlXgDaQYP3tZrLjb77+NE6sOYOUlrdi9hBaxpO4fokCjrlNBWcnKVaOBtd37d9pr0XWLip2HTpv mVHhuqMPL0VSJSFJDBSGhb1g7IHRySIZ0C14ge9aKGZwEBtVxIpe6Vj X-Received: by 2002:a05:600c:444f:b0:480:32da:f338 with SMTP id 5b1f17b1804b1-483201e4d03mr113118775e9.14.1770537343608; Sat, 07 Feb 2026 23:55:43 -0800 (PST) Received: from ?IPV6:2003:df:bf2d:e300:f72a:85fc:d143:8f3c? (p200300dfbf2de300f72a85fcd1438f3c.dip0.t-ipconnect.de. [2003:df:bf2d:e300:f72a:85fc:d143:8f3c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48320983f18sm87092175e9.8.2026.02.07.23.55.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Feb 2026 23:55:42 -0800 (PST) Message-ID: <9ecadaa2-0f6b-411f-9faf-0ecc93b26bc2@gmail.com> Date: Sun, 8 Feb 2026 08:55:40 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 2/2] scripts: checkpatch: add RUST_UNWRAP lint To: Jason Hall , Miguel Ojeda Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Joe Perches , Boqun Feng , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Dirk Behme , Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Miguel Ojeda References: <20260207224907.234815-1-jason.kei.hall@gmail.com> <20260207224907.234815-3-jason.kei.hall@gmail.com> Content-Language: de-AT-frami, en-US From: Dirk Behme In-Reply-To: <20260207224907.234815-3-jason.kei.hall@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 07.02.26 23:49, Jason Hall wrote: > 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. I wonder if we could add some outcome from the mailing list discussion to the commit message? E.g. what we consider to be false positives, the handling of them and what we suppose to be fixed etc. > Suggested-by: Miguel Ojeda > Link: https://github.com/Rust-for-linux/linux/issues/1191 > Signed-off-by: Jason Hall > --- > scripts/rust_checkpatch.pl | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/scripts/rust_checkpatch.pl b/scripts/rust_checkpatch.pl > index 56c1bc29d3f2..fa7adaed264c 100644 > --- a/scripts/rust_checkpatch.pl > +++ b/scripts/rust_checkpatch.pl > @@ -9,7 +9,21 @@ use warnings; > sub process_rust { > my ($line, $rawline, $herecurr) = @_; > > - # Reserve for future Rust-specific lints > + # Check for Rust unwrap/expect usage. > + # We skip lines that are already comments, assert macros (common in tests), > + # or have a '// PANIC:' justification. > + if ($line =~ /^\+/) { > + if ($line =~ /(?:\.|::)(?:unwrap|expect)\s*\(/ && Whats about the `.expect()` topic discussed in https://lore.kernel.org/rust-for-linux/a798e6a368639f7a1ce633a6dfecd088d6ed4123.camel@perches.com/T/#m00723ad673727036e5fcf96a35f2f231ec9de31f https://lore.kernel.org/rust-for-linux/a798e6a368639f7a1ce633a6dfecd088d6ed4123.camel@perches.com/T/#m5604274a633ef33eb474f95b54f797843d0fe1dd ? > + $rawline !~ /\/\/\s*PANIC:/ && > + $line !~ /^\+\s*\/\// && > + $line !~ /^\+\s*assert/) { > + return ("RUST_UNWRAP", > + "unwrap() and expect() should generally be avoided in Rust kernel code.\n" . > + "If the use is intended, please justify it with a '// PANIC:' comment.\n" . > + "See: https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust\n" . > + $herecurr); > + } > + } > return (); > } Just for the logs: Running this on e.g. https://lore.kernel.org/rust-for-linux/20260207-binder-shrink-vec-v3-v3-3-8ff388563427@cock.li/ gives $ ./scripts/checkpatch.pl 0001-rust-alloc-add-KUnit-tests-for-Vec-shrink-operations.patch WARNING: unwrap() and expect() should generally be avoided in Rust kernel code. If the use is intended, please justify it with a '// PANIC:' comment. See: https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust #52: FILE: rust/kernel/alloc/kvec.rs:1524: + let mut v: VVec = VVec::with_capacity(initial_capacity, GFP_KERNEL).unwrap(); ... total: 0 errors, 21 warnings, 189 lines checked (note: all 21 warnings are from `unwrap()`) I'm not sure if it makes me happy to ignore these 21 warnings as false positives ;) Best regards Dirk