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 X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8E14C2BBCD for ; Wed, 16 Dec 2020 04:44:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 81C0D2311F for ; Wed, 16 Dec 2020 04:44:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81C0D2311F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1747D8D000E; Tue, 15 Dec 2020 23:44:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 123CD6B0074; Tue, 15 Dec 2020 23:44:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03DDE8D000E; Tue, 15 Dec 2020 23:44:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id DC01D6B0073 for ; Tue, 15 Dec 2020 23:44:35 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A6D7A8249980 for ; Wed, 16 Dec 2020 04:44:35 +0000 (UTC) X-FDA: 77597904510.09.play48_0214ec527429 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 905C7180AD80F for ; Wed, 16 Dec 2020 04:44:35 +0000 (UTC) X-HE-Tag: play48_0214ec527429 X-Filterd-Recvd-Size: 2590 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 04:44:35 +0000 (UTC) Date: Tue, 15 Dec 2020 20:44:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608093874; bh=/gxezh6NM1NwxoAGsy91PYSYl0FkSI3yBwotYuFmZ1k=; h=From:To:Subject:In-Reply-To:From; b=RF7UAKvZf0YuHvof8rbSNeK0+cz0+eRy8jxkdv3v5vRtLtuDvgoY4T0+n2tTyYtKs AtVLpGYoxx8f+1rq821hC8yjxkztbmubiR7QpmX7yTooOHx8yFvXH8piAQUOODgYkR ruT4irGB1RvlXEoEh77+eFa9JZskM59ukim3dwUs= From: Andrew Morton To: akpm@linux-foundation.org, joe@perches.com, julia.lawall@inria.fr, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, trix@redhat.com Subject: [patch 41/95] checkpatch: allow --fix removal of unnecessary break statements Message-ID: <20201216044433.zYvlm9_yH%akpm@linux-foundation.org> In-Reply-To: <20201215204156.f05ec694b907845bcfab5c44@linux-foundation.org> User-Agent: s-nail v14.8.16 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: From: Joe Perches Subject: checkpatch: allow --fix removal of unnecessary break statements switch/case use of break after a return, goto or break is unnecessary. There is an existing warning for the return and goto uses, so add break and a --fix option too. Link: https://lkml.kernel.org/r/d9ea654104d55f590fb97d252d64a66b23c1a096.camel@perches.com Signed-off-by: Joe Perches Cc: Julia Lawall Cc: Tom Rix Signed-off-by: Andrew Morton --- scripts/checkpatch.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/scripts/checkpatch.pl~checkpatch-allow-fix-removal-of-unnecessary-break-statements +++ a/scripts/checkpatch.pl @@ -3699,12 +3699,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 the previous line is a goto, return or break +# 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); + if ($prevline =~ /^\+$tabs(goto|return|break)\b/) { + if (WARN("UNNECESSARY_BREAK", + "break is not useful after a $1\n" . $hereprev) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + } } } _