[PATCH 3/4] checkpatch: don't warn about BUG() in userspace code
From: Kir Kolyshkin
Date: Thu Oct 22 2026 - 18:45:42 EST
The AVOID_BUG check says "Do not crash the kernel unless it is absolutely
unavoidable". This makes no sense for userspace code under tools/, where
BUG() and BUG_ON() are assert-like helpers provided by the kernel API
shims (e.g. in tools/testing/radix-tree), and crashing a test program on
an unexpected condition is fine.
Use is_userspace() to skip the check for such files.
Signed-off-by: Kir Kolyshkin <kolyshkin@xxxxxxxxx>
---
scripts/checkpatch.pl | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a97d5748878b..be0e0493d4a2 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4924,8 +4924,9 @@ sub process {
}
}
-# do not use BUG() or variants
- if ($line =~ /\b(?!AA_|BUILD_|IDA_|KVM_|RWLOCK_|snd_|SPIN_)(?:[a-zA-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)?\s*\(/) {
+# do not use BUG() or variants (does not apply to userspace)
+ if (!is_userspace($realfile) &&
+ $line =~ /\b(?!AA_|BUILD_|IDA_|KVM_|RWLOCK_|snd_|SPIN_)(?:[a-zA-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)?\s*\(/) {
my $msg_level = \&WARN;
$msg_level = \&CHK if ($file);
&{$msg_level}("AVOID_BUG",
--
2.56.0