Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751905AbbFHFoQ (ORCPT ); Mon, 8 Jun 2015 01:44:16 -0400 Received: from smtprelay0021.hostedemail.com ([216.40.44.21]:38912 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751350AbbFHFoE (ORCPT ); Mon, 8 Jun 2015 01:44:04 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:800:960:966:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1461:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2196:2197:2199:2200:2393:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3653:3865:3866:3867:3868:3870:3871:3872:3873:3874:4385:5007:6119:6261:6691:7809:7903:10004:10400:10848:11026:11232:11473:11658:11914:12294:12296:12517:12519:12555:12663:13149:13230:13618:14093:14097:14394:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: part14_2340edf25ae01 X-Filterd-Recvd-Size: 3473 Message-ID: <1433742241.2742.4.camel@perches.com> Subject: [PATCH] checkpatch: Warn on BUG and BUG_ON uses From: Joe Perches To: Linus Torvalds , Andrew Morton Cc: Tejun Heo , Louis Langholtz , Linux Kernel Mailing List , trivial@kernel.org, Rusty Russell Date: Sun, 07 Jun 2015 22:44:01 -0700 In-Reply-To: References: <1433721270-9182-1-git-send-email-lou_langholtz@me.com> <20150608000007.GA3543@mtj.duckdns.org> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.11-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2536 Lines: 77 Spake Linus: > Hell no. > > Stop with the random BUG_ON() additions. > > I have said this before, and apparently I need to sat this again, and > probably I will have to say it in the future. > > We don't add BUG_ON's for random reasons. > > The *ONLY* acceptable reason for a BUG_ON() is if the machine is dead > anyway because of some major internal corruption. > > We have too many BUG_ON's. We've had people add BUG_ON's because "this > cannot happen", and then it turns out they were wrong, and they just > killed the machine. > > Dammit, there's no reason to add a BUG_ON() here in the first place, > and the reason of "but but it's an unused error return": is f*cking > retarded. > > Stop this idiocy. We don't write crap code just to satisfy some random > coding standard or shut up a compiler error. > > At most, it could be a "WARN_ON_ONCE()". Maybe even just silently > ignore the error. But BUG_ON()? Hell no. > > NO NO NO. > > Quite frankly, if you want to add error handling, then dammit, add it > right. And no, BUG_ON() is _never_ proper error handling. > > BUG_ON() is for things like "uhhuh, somebody is trying to free a page > that is already free". That is some serious internal corruption. > > BUG_ON() is _not_ for "I'm not doing any error handling, so I'll > sprinkle random lines of BUG_ON() like fairy dust to make the compiler > happen". > > Really. I'm getting very tired indeed of people adding BUG_ON's like > that. Stop it. Signed-off-by: Joe Perches --- scripts/checkpatch.pl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 69c4716..f3daa4e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3423,12 +3423,11 @@ sub process { } } -# # no BUG() or BUG_ON() -# if ($line =~ /\b(BUG|BUG_ON)\b/) { -# print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n"; -# print "$herecurr"; -# $clean = 0; -# } +# avoid BUG() or BUG_ON() + if ($line =~ /\b(BUG|BUG_ON)\b/) { + WARN("BUG", + "Avoid using $1 unless there is a serious corruption - try to use WARN_ON & recovery code instead\n" . $herecurr); + } if ($line =~ /\bLINUX_VERSION_CODE\b/) { WARN("LINUX_VERSION_CODE", -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/