Include the prefixed and postfixed BUG/BUG_ON variants like VM_BUG_ON
that can kill the kernel.  Exclude the BUILD and lower case variants.

$ grep -rP --include=*.[ch] -oh "\w+_BUG_ON\w*" * | \
  sort | uniq -c | sort -rn
   1838 BUILD_BUG_ON
    632 snd_BUG_ON
    263 VM_BUG_ON_PAGE
    260 VM_BUG_ON
     97 GEM_BUG_ON
     57 SNIC_BUG_ON
     49 EFX_BUG_ON_PARANOID
     45 BUILD_BUG_ON_ZERO
     45 BUILD_BUG_ON_MSG
     30 B43legacy_BUG_ON
     24 VM_BUG_ON_VMA
     21 BUILD_BUG_ON_NOT_POWER_OF_2
     16 PCPU_SETUP_BUG_ON
     15 GLOCK_BUG_ON
     12 LOGFS_BUG_ON
     11 RWLOCK_BUG_ON
     10 VIRTUAL_BUG_ON
      9 SPIN_BUG_ON
      9 BUILD_BUG_ON_INVALID
      8 UNWINDER_BUG_ON
      8 DEBUG_SPINLOCK_BUG_ON
      7 VM_BUG_ON_MM
      7 LIST_BL_BUG_ON
      6 BUILD_BUG_ON_NULL
      5 MAYBE_BUILD_BUG_ON
      4 VM_BUG_ON_PGFLAGS
      4 SSB_BUG_ON
      4 HAVE_ARCH_BUG_ON
      4 BIO_BUG_ON
      3 DCCP_BUG_ON
      3 __BUILD_BUG_ON_NOT_POWER_OF_2
      2 __BUG_ON_cond
      2 __BUG_ON
      1 CONFIG_BUG_ON_DATA_CORRUPTION

Suggested-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: Joe Perches <j...@perches.com>
---
 scripts/checkpatch.pl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3373c65fef1c..be796704e218 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3725,8 +3725,9 @@ sub process {
                        }
                }
 
-# avoid BUG() or BUG_ON()
-               if ($line =~ /\b(?:BUG|BUG_ON)\b/) {
+# avoid BUG() or BUG_ON() like mechanisms (exclude BUILD_BUG)
+               if ($line =~ /\b((?:[A-Z_]+_)?BUG(?:_ON(?:_[A-Z_]+)?))\s*\(/ &&
+                   $1 !~ /BUILD/) {
                        my $msg_type = \&WARN;
                        $msg_type = \&CHK if ($file);
                        &{$msg_type}("AVOID_BUG",

Reply via email to