Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1589239pxb; Fri, 1 Oct 2021 14:13:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZukZMUQf1BQyy8S4cQBtXugz3EdfDIhw90o2PjeQQPqF7TkC1IBSsC4ckoyferZk0IjEv X-Received: by 2002:a63:bf07:: with SMTP id v7mr140174pgf.475.1633122812569; Fri, 01 Oct 2021 14:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633122812; cv=none; d=google.com; s=arc-20160816; b=0mcXDJ1X928KVtO+FxE3fJo+jHGwk2+a0EW2tx6b/F+bvEFWCeHosP7J5yca3fPKmB JkcZfzpx/uPEc3PDDrTIpi0+Tlx35EGQ/cwKy8v45gDLRKn+AdOBsF1k65p12dYBAf0G Cy9xNYbxXD4zH4Lnn30gYoS19Y7o5mpX9tNj4tN0UwQQk8+BynDVE9OVkeKFLMqKwmX9 otTljyZSLPJOlOMkwSttB56iG7CZWDk9xncnXav3HoKiYZ0iYbNHkd9afO39Y0nIA81Y UWW7BUD5RBV2ltbkJIlCr3AqiSUEsiW2n4YBMl4ITOeX8Gc9PAtyx/ipdSx74gR4p62P 7Msg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=HJmrh/fTfFKrkkU0cURPLfUf1qzxzbLme5ZLHP9MktM=; b=EUjlbRHVHKg3INVP2e1XHp+LMVwwnFbZofGnqgnZt1CEJL5Qdd3wl5fKhAMptwavYs S/x2pGKRUApRrxxP2G8j+R2vWGVYwf+haeTDhqrm2wbs+yBNB0HSddCZU/IqvL5a640Y ZrP38zCGWEKT7R9UnczpvxWujcnStMi9J++8DBXYP7FynUf4ExyZxGipMi3ObqDBSYD7 VLsfuuTSQtIkJa0RlB9pqlISdhBLlYOwPHDB8P97yrjOP558Je7+56z0llrV/zO3aCn6 KRf8hL+Bq3YSd5J1/4nxaKZUH20UD3YPLteRPg6vwLuXpVDZWFySu5Q+YorTa3KVfyOY RC6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si9061991pfc.264.2021.10.01.14.13.20; Fri, 01 Oct 2021 14:13:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354833AbhJAVLO (ORCPT + 99 others); Fri, 1 Oct 2021 17:11:14 -0400 Received: from smtprelay0211.hostedemail.com ([216.40.44.211]:51846 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355080AbhJAVLG (ORCPT ); Fri, 1 Oct 2021 17:11:06 -0400 Received: from omf13.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 8C0A3180995DD; Fri, 1 Oct 2021 21:09:20 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf13.hostedemail.com (Postfix) with ESMTPA id A4BE51124F4; Fri, 1 Oct 2021 21:09:19 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2] checkpatch: add check for continue statement in UNNECESSARY_ELSE From: Joe Perches To: Utkarsh Verma , Andy Whitcroft Cc: Dwaipayan Ray , Lukas Bulwahn , linux-kernel@vger.kernel.org Date: Fri, 01 Oct 2021 14:09:18 -0700 In-Reply-To: <20211001204705.7448-1-utkarshverma294@gmail.com> References: <91569a87ac55da392fa894e8ad55292b98c558f3.camel@perches.com> <20211001204705.7448-1-utkarshverma294@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: A4BE51124F4 X-Spam-Status: No, score=6.17 X-Stat-Signature: 1yxmnryimh8gfyunrfxp7ojkkq9ptajq X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX189yS0gSYU1iALO3xmt6CU+yHZePHjVIDk= X-HE-Tag: 1633122559-58868 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2021-10-02 at 02:17 +0530, Utkarsh Verma wrote: > UNNECESSARY_ELSE only checks for the usage of else after a return or > break. But the same logic is also true for continue statement. > > else used after a continue statement is unnecessary. So add a test > for continue statement also. [] > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -4011,15 +4011,15 @@ sub process { > ? > > ?# check indentation of any line with a bare else > ?# (but not if it is a multiple line "if (foo) return bar; else return baz;") > -# if the previous line is a break or return and is indented 1 tab more... > +# if the previous line is a break or continue or return and is indented 1 tab more... > ? if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) { > ? my $tabs = length($1) + 1; > - if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ || > + if ($prevline =~ /^\+\t{$tabs,$tabs}(?:break|continue)\b/ || > ? ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ && > ? defined $lines[$linenr] && > ? $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) { > ? WARN("UNNECESSARY_ELSE", > - "else is not generally useful after a break or return\n" . $hereprev); > + "else is not generally useful after a break or continue or return\n" . $hereprev); > ? } > ? } > ? > Maybe make the output specific to the break/continue/return (untested) if ($prevline =~ /^\+\t{$tabs,$tabs}(break|continue|return)\b/ && !($1 == "return" && defined $lines[$linenr] && $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) { WARN("UNNECESSARY_ELSE", "else is not generally useful after a $1\n" . $hereprev);