From patchwork Tue Jul 8 19:57:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 4509901 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 11A9ABEEAA for ; Tue, 8 Jul 2014 19:58:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D9AA201DC for ; Tue, 8 Jul 2014 19:58:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0EED201C7 for ; Tue, 8 Jul 2014 19:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753324AbaGHT5q (ORCPT ); Tue, 8 Jul 2014 15:57:46 -0400 Received: from smtprelay0081.hostedemail.com ([216.40.44.81]:38916 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753293AbaGHT5q (ORCPT ); Tue, 8 Jul 2014 15:57:46 -0400 Received: from filter.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id D8462C211F; Tue, 8 Jul 2014 19:57:44 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2, 0, 0, , d41d8cd98f00b204, joe@perches.com, :::::::::::::, RULES_HIT:41:355:379:541:800:960:973:982:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3653:3865:3866:3868:3870:3871:4321:4823:5007:7652:10004:10400:10848:11232:11658:11914:12043:12296:12438:12517:12519:12555:13069:13161:13229:13255:13311:13357: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: stem91_4351bd5dfb402 X-Filterd-Recvd-Size: 2284 Received: from [192.168.43.247] (208.sub-70-197-70.myvzw.com [70.197.70.208]) (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA; Tue, 8 Jul 2014 19:57:42 +0000 (UTC) Message-ID: <1404849460.932.35.camel@joe-AO725> Subject: [PATCH] checkpatch: Warn on break after goto or return with same tab indentation From: Joe Perches To: Andrew Morton , Fabian Frederick Cc: Antti Palosaari , linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , linux-media@vger.kernel.org, Andy Whitcroft Date: Tue, 08 Jul 2014 12:57:40 -0700 In-Reply-To: <20140709041215.3e1083201f5a400c37b820b0@skynet.be> References: <1404840181-29822-1-git-send-email-fabf@skynet.be> <53BC3A0E.4060505@iki.fi> <20140709041215.3e1083201f5a400c37b820b0@skynet.be> X-Mailer: Evolution 3.10.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using break; after a goto or return is unnecessary so emit a warning when the break is at the same indent level. So this emits a warning on: switch (foo) { case 1: goto err; break; } but not on: switch (foo) { case 1: if (bar()) goto err; break; } Signed-off-by: Joe Perches --- > AFAIK there's still no automatic detection of those cases. There can be now... scripts/checkpatch.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 496f9ab..fc22f22 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2439,6 +2439,16 @@ sub process { } } +# check indentation of a line with a break; +# if the previous line is a goto or return and is indented the same # of tabs + if ($sline =~ /^\+([\t]+)break\s*;\s*$/) { + my $tabs = $1; + if ($prevline =~ /^\+$tabs(?:goto|return)\b/) { + WARN("UNNECESSARY_BREAK", + "break is not useful after a goto or return\n" . $hereprev); + } + } + # discourage the addition of CONFIG_EXPERIMENTAL in #if(def). if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_EXPERIMENTAL\b/) { WARN("CONFIG_EXPERIMENTAL",