Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp860898rwe; Wed, 24 Aug 2022 10:09:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR4U8EuQpYxu0fAbGuBSn++lyw5mrM96/wjZ0xNihF2h4U5dr4hnVWxTCBDtt2doGPAccUrV X-Received: by 2002:a05:6402:538a:b0:43a:298e:bc2b with SMTP id ew10-20020a056402538a00b0043a298ebc2bmr8825edb.125.1661360942384; Wed, 24 Aug 2022 10:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661360942; cv=none; d=google.com; s=arc-20160816; b=idSk/2u5SeFubjS/d6noZXNc99Zql4MdP0WxyWP/VFlDTzH82B6DBLBr2v4KKVFkMN 1MNdLTLJEkRLZfXk0sHUM+jiVJU5UiRwPWiW/E1/ur2Ot38SOXUOrecFIW8fZmbabidQ bou1S+VrRjWbFgmj8s+LoRlvllhKCop7svE99Gnl+R8B523U+a3MDP+FZWDdvOUBYMFd eo+Ls2+HfC7H2KvEvsTb/3oJNzuCyCMvaP9nslTaGjZi706G+grr1mJ6q3sPt6vfRFrz m1JIqNOaiYqBSfNXUwNhaY+uSRODC4/Zevx4PibVHWJ0y5/M3NFJXgRJVFt/D8dVLmvb skog== 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=UXUvPXR+b9lqF8hwT6ic9kgmL6Hea0lIAs1c1MqWYvI=; b=WQYHjdgTTQH7baeNZU3FZaIlr6PtPwhDZF4lLh/1Zp3LQJMQXWb9kWOgrJyMwRNsOr EsDcPXpz+7CI4FWnmHlj/epiAtAPt06kQDUQASGNSOBrdpqVKabDniwSl3gu17lxn1A+ D98fDHB8wLbraQ8Tzyb/kiEB8G/DF5K3kH5mLVeB0XUesqbB2tXCZtWzFESRWOQ6YDma gkCCnqdjznmPqneAyV7wkT8N+LJLq+Il1v3kRmvG3KaAtlA/cGJELry/F5CagMtuvm+c K8pn8c4CF+lNmvSf2COp9oGL9u+Dox1Tit9aAq+7uTOvvlPX5TL8W5cR2yyfjLFislwj G0Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="FHo4aXd/"; 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 x19-20020a170906b09300b0073d6ad5693esi2098218ejy.388.2022.08.24.10.08.34; Wed, 24 Aug 2022 10:09:02 -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="FHo4aXd/"; 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 S239493AbiHXQdb (ORCPT + 99 others); Wed, 24 Aug 2022 12:33:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239979AbiHXQbV (ORCPT ); Wed, 24 Aug 2022 12:31:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ADF6915D4 for ; Wed, 24 Aug 2022 09:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661358679; 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=UXUvPXR+b9lqF8hwT6ic9kgmL6Hea0lIAs1c1MqWYvI=; b=FHo4aXd/rsP/qXV8VfB5JczrT0tpAFivQkA2a8cqiNDVOlgsACHb2dq1LDCTmdMNn2P/sk C3S2ADyzP4XWgYvR0YsYHgR+YmI4R1lhlasGr/KdJ+tFTyMyTeJw/J6WWF1QEusWucTVIn TVj6ZFuckwgI/+XVDRAacstVmHu0N0M= 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-552-SCBzPGAuN0qxwGul-CpxkQ-1; Wed, 24 Aug 2022 12:31:14 -0400 X-MC-Unique: SCBzPGAuN0qxwGul-CpxkQ-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 140248039A1; Wed, 24 Aug 2022 16:31:14 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.193.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EF3840315A; Wed, 24 Aug 2022 16:31:10 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, kexec@lists.infradead.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 Subject: [PATCH RFC 2/2] checkpatch: warn on usage of VM_BUG_ON() and friends Date: Wed, 24 Aug 2022 18:31:00 +0200 Message-Id: <20220824163100.224449-3-david@redhat.com> In-Reply-To: <20220824163100.224449-1-david@redhat.com> References: <20220824163100.224449-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 friends as well. While at it, make it clearer that the kernel really shouldn't be crashed. Note that there are some other *_BUG_ON flavors, but they are not all bad: for example, KVM_BUG_ON() only triggers a WARN_ON_ONCE and then flags KVM as being buggy, so we'll not care about them for now here. [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..4c18acf17032 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(), BUG_ON(), VM_BUG_ON() and friends. + if ($line =~ /\b(?:BUG|BUG_ON|VM_BUG_ON|VM_BUG_ON_[A-Z]+)\b/) { 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(), BUG_ON(), VM_BUG_ON(), ...\n" . $herecurr); } # avoid LINUX_VERSION_CODE -- 2.37.1