Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3835239rwb; Tue, 20 Sep 2022 05:33:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4d7AzVHO3G/obKziEgRuCOGqCtOjnfUSan0BJN6GNg2mO4b/3YgPT61UnslBtvA18ld29F X-Received: by 2002:a05:6a00:17a3:b0:540:97a3:f7a9 with SMTP id s35-20020a056a0017a300b0054097a3f7a9mr22931695pfg.12.1663677193503; Tue, 20 Sep 2022 05:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663677193; cv=none; d=google.com; s=arc-20160816; b=F4I/kXueoIxR78jV8qckXzfv6hyk1XeeTszaAWWmt6QwUjXSIilIG69MlKVqIpFcRy 0CAutwaGup2kiCxlvqdyKjtbpP3KDod1i2UUJQxIa1uxvAVsAPyUbRF28ml9QBjpSwym 8dX8KGCs+4y0ra933F8T+tm3jPWRz7CeLEC4NbI4Bd98eljdpw2viufYOukkq3G8zuHR 3UnjaavBgcQqCLXDJev6fYoAajby3zivJ76UGJuFcw55pkw9cR0FUCZfkzs2950Z6XUO 7Wqj8pKhkn5Lh8eXwfSe5ggGof4+//vjeghKqjjq91JX/RA0GDBnoGURVjSY/Ny9INMd yDwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ITgZ+FEhdrS2y8XEyUzkVY3PfF+vnYBUViWp7eHKbVA=; b=qU7FIVrgKX0Kj8HN0uKwU63nGE5GrJBqYHPI4rOvmyIbKG/gztMTXNCRvJjhGsN46d 1nLV3vCqOz2mzS0M3ws6G/keM2oebquCE7MLvJuZBwWT9iGsQ7rjSNyJrXaDDyCI00xg 4zarTxUSVDwnnot0IUjXFXuyLLdwktSv41YfhClvi9DqBvwS7k5LEsesl/sZ2FDh0Jf0 La6JRODPzji+S3ZVQp1KfWeKrQrX9+H6sAPlKSyln5pUQYUnQ3s85M4AhO4c2MSPHrU4 vq1Q1x1IUUX/8eVpC/RbBjwqQgIyelSDebHcbl3oagZXQia27Al/cOnuHYDpcv8ZhDIa mitA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EEPRPztf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020a17090abc8c00b00200ae8c504dsi1618257pjr.65.2022.09.20.05.32.59; Tue, 20 Sep 2022 05:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EEPRPztf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbiITMXc (ORCPT + 99 others); Tue, 20 Sep 2022 08:23:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbiITMX1 (ORCPT ); Tue, 20 Sep 2022 08:23:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2A475389 for ; Tue, 20 Sep 2022 05:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663676605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ITgZ+FEhdrS2y8XEyUzkVY3PfF+vnYBUViWp7eHKbVA=; b=EEPRPztfhOM4l8U7nHFWB8ye50Bk1ZMvAqrgz7Fvpg4yUO8DTa4vuFdnzctqsLQm8sdik/ /WSgptTfRIPCnwOCn3ONLqX4Bi0VweUrbGIVmJU6sNdj5p/hAQxykTcawk4TFId5LrrQbh EqV3NOL/+ObggbuZx8JDGrqodnPAbbQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-287-5ll2Ea3jNV6xCqe3I2yCaA-1; Tue, 20 Sep 2022 08:23:22 -0400 X-MC-Unique: 5ll2Ea3jNV6xCqe3I2yCaA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC1DA38173C1; Tue, 20 Sep 2022 12:23:21 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.195.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 082A8C15BB5; Tue, 20 Sep 2022 12:23:17 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, David Hildenbrand , Linus Torvalds , Andrew Morton , Ingo Molnar , David Laight , Jonathan Corbet , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Baoquan He , Vivek Goyal , Dave Young , Jani Nikula , Michael Ellerman , Nicholas Piggin , Christophe Leroy Subject: [PATCH v1 3/3] checkpatch: warn on usage of VM_BUG_ON() and other BUG variants Date: Tue, 20 Sep 2022 14:23:02 +0200 Message-Id: <20220920122302.99195-4-david@redhat.com> In-Reply-To: <20220920122302.99195-1-david@redhat.com> References: <20220920122302.99195-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org checkpatch does not point out that VM_BUG_ON() and friends should be avoided, however, Linus notes: VM_BUG_ON() has the exact same semantics as BUG_ON. It is literally no different, the only difference is "we can make the code smaller because these are less important". [1] So let's warn on VM_BUG_ON() and other BUG variants as well. While at it, make it clearer that the kernel really shouldn't be crashed. As there are some subsystem BUG macros that actually don't end up crashing the kernel -- for example, KVM_BUG_ON() -- exclude these manually. [1] https://lore.kernel.org/r/CAHk-=wg40EAZofO16Eviaj7mfqDhZ2gVEbvfsMf6gYzspRjYvw@mail.gmail.com Signed-off-by: David Hildenbrand --- scripts/checkpatch.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 79e759aac543..21f3a79aa46f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4695,12 +4695,12 @@ sub process { } } -# avoid BUG() or BUG_ON() - if ($line =~ /\b(?:BUG|BUG_ON)\b/) { +# do not use BUG() or variants + if ($line =~ /\b(?!AA_|BUILD_|DCCP_|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", - "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr); + "Do not crash the kernel unless it is unavoidable - use WARN_ON_ONCE & recovery code (if reasonable) rather than BUG() or variants.\n" . $herecurr); } # avoid LINUX_VERSION_CODE -- 2.37.3