From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 048A8C6FA8E for ; Fri, 23 Sep 2022 11:34:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9979D8000A; Fri, 23 Sep 2022 07:34:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9200080007; Fri, 23 Sep 2022 07:34:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 773628000A; Fri, 23 Sep 2022 07:34:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6585180007 for ; Fri, 23 Sep 2022 07:34:47 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 321E41415FF for ; Fri, 23 Sep 2022 11:34:47 +0000 (UTC) X-FDA: 79943143014.11.1ECD3DB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id E113340020 for ; Fri, 23 Sep 2022 11:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663932886; 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=zm4C72SW81Cbx3tNeB9UTn3z5INQ0ekYL1eCBmS/H58=; b=X/n5ihwIXGrGcdwP5IhJC0nyLS1bV2LtlFI6ZtLqhr7T2SyADfdeVyKmEAshvfKac0UKuT oNvWa6uCmZutSxDmW8/xkCQJ4c5e0gOVzc1WwFfQSPxkCCI1MkYaG/zSfz7o1dNhfi/L++ Zin352YQpnSZWu0Mzstz8WM7/7jF6sI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-q_Vg4V3iMAWbmNFQHcW4Cw-1; Fri, 23 Sep 2022 07:34:43 -0400 X-MC-Unique: q_Vg4V3iMAWbmNFQHcW4Cw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5AAA7811E67; Fri, 23 Sep 2022 11:34:42 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55027492B06; Fri, 23 Sep 2022 11:34:38 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.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 , Akira Yokosawa , Kalle Valo , "Daniel K ." Subject: [PATCH v2 2/2] checkpatch: warn on usage of VM_BUG_ON() and other BUG variants Date: Fri, 23 Sep 2022 13:34:25 +0200 Message-Id: <20220923113426.52871-3-david@redhat.com> In-Reply-To: <20220923113426.52871-1-david@redhat.com> References: <20220923113426.52871-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663932886; a=rsa-sha256; cv=none; b=i/6VzJQhRXi0NO/3H9JIFqHvv+Qzl368fVts0WNNob9ozy/4Ke+LR//IE7dqS1AwnX0lJa 4kxcR1lmBERRyZoG9gxx4Kj1dBC5yHV12rMvjeBMh/UfjDIeiBRz6T10GW9JNc93482M9I lOvzufVXpDTb3S/V47q7bHk9JEHmwmM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="X/n5ihwI"; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663932886; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zm4C72SW81Cbx3tNeB9UTn3z5INQ0ekYL1eCBmS/H58=; b=5wBPDpWSCkd6tqmyXAv0A6NRl0GO0cglDxIs8qT1LRIHCyeQsLc+5/KtPUUJQHdHUTcTFs t0tDz5LkVJku7+As+ZcCgcdD7GeiKyoqlU4Wf6lLjPP8OVRjIXa3wxcAAGG5XgFf8/rIcm HzZeKsH91lqbt2Jrs2iGjBKLOIGfPrc= X-Stat-Signature: a8b6q4dj87pm4t7cdjupf9k65u765xq3 X-Rspamd-Queue-Id: E113340020 X-Rspam-User: X-Rspamd-Server: rspam11 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="X/n5ihwI"; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1663932886-464074 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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..5ca0039f216a 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 absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants\n" . $herecurr); } # avoid LINUX_VERSION_CODE -- 2.37.3