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=unavailable 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 7D012C4361B for ; Wed, 16 Dec 2020 04:45:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37A202313F for ; Wed, 16 Dec 2020 04:45:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725934AbgLPEpO (ORCPT ); Tue, 15 Dec 2020 23:45:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:50598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgLPEpO (ORCPT ); Tue, 15 Dec 2020 23:45:14 -0500 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 Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org 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); + } } } _