Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2560181pxb; Sat, 2 Oct 2021 22:14:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJze9TFfQqSOklwLwrnniVIQdvC4oQwytP6RvBCrsNlzHvgFT8ItWKFeMXYIk2xEV5gkvxfg X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr8710471ejk.218.1633238092575; Sat, 02 Oct 2021 22:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633238092; cv=none; d=google.com; s=arc-20160816; b=TOCmk6NwUur404R5KyFS32LLSLyvoKilOYRN47euswiNdlBR0MKxfXPbhoanFt7XgJ bm42vwIOfz2t+DYunJSUKWQrdy5AUFHUiwGvH3b8ELI93Cv63gRL/GqqQ99l7GIdPq0s nMi96o5+dYwRWOae3g+aZHCpKfVtoJq2vBs1DiSc/oeId7NP3zXesE67vYvjxBm4usjt 73C4u3KrnzB68Wm1WMYcCtw1Kpvtdrb/UZOWo1ANk8Aa900w1qHiQcuSeKNkcY771sE1 Mpxz7sqTSkuf3ldyU5pTeIk6PWQGyLRYjXCL+gF2G9EJeOZa/IjX1jgvZxmVMeEphk4K iGlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7X9wrDB6kU7Zn7sIQW2J6Ll13ujNfojISEAcJyTSWLk=; b=idNz6UaW/vBAx8EArycaX8zed2wLVfmtDows/jh9SSf+kBU6HPhtg+OKrN2YyQAHKb gcqzjqvn3HhdX3wq0aob5rqeNRsHs2KGhnQE9oJ/jn4o9bzyCvGR3bJidPZ7KwnKPZ69 VZFcushmBo+zcIhUN2hguwPoze3ODzgCFulZjWyDcBWpNPVo7HzcyaNTtpSy7gaRXtDU RFe+ioHOkKLyazlKJWByY3JZmb2M89pBtOaEYSRqL+6S7og/ATPPJJ4IAXldxos9Fld+ BHm90DCAs30fIAkugC8snJrolTwBIh7n9sbSJ09Dhg0Nnmo8dC5B7GANHW4N6NCvfkCD 5F7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jLtcR920; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i4si13213010edv.284.2021.10.02.22.14.25; Sat, 02 Oct 2021 22:14:52 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jLtcR920; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229585AbhJCFO0 (ORCPT + 99 others); Sun, 3 Oct 2021 01:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbhJCFOZ (ORCPT ); Sun, 3 Oct 2021 01:14:25 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C197C0613EC for ; Sat, 2 Oct 2021 22:12:38 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id s64so26796753yba.11 for ; Sat, 02 Oct 2021 22:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7X9wrDB6kU7Zn7sIQW2J6Ll13ujNfojISEAcJyTSWLk=; b=jLtcR920mB32Erq/w8ERUFrtfop3VMZPzSXioNVFO5nkrxWjjnS27eHpdQDOcIz6aS wEQ1DKp3HrnyGj3PaqCoaQB1sEV0pI1w9QriH7/HdLjWMAGmPdmsOytb4Ua0KxQpqID6 PJWwxyXDh+F9IAAv5GTLJXkgoAo9oKQyJb8mwMNhgM8VQNnXjwFRy9GgT/4G2TdJtMyc BgoPBeSob15CeOJrJuXChfrwMDk8uH4VWsPLXq8cWQlZ0Jehp8szuaC4iqHBZMwZof3Q /iekaLW4/WSwnC0xU9cG4/VUj70irEa7qVOpZuG3/uvAQDT6NXvorfLrhniiyFFhEnXM Q4iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7X9wrDB6kU7Zn7sIQW2J6Ll13ujNfojISEAcJyTSWLk=; b=NvcpQ15Cx/prb1mmSFHht+E+ujkZUTqFLS2n1Dv0/WncHzG+Jds6cVfvasa0r7yS6P xJX9o44SrTaurVt4OEaBb72kmMFtoU303fVgkhQdYyrJMs7wE5jEt3IFHKIsX/zAahEa U+zFX18FmwmRZkgmPcbfSlLs0eJNaZqLKmUCjAVMQ88pb3+wm4fy+DfXNEuEYNxGIHga jMRm/nYOsYsXCjvaDZ0GUfilMoJiXm300uuKE1AdNatLCr7kAXUmWhTv5+b+3V6Zv9MY +PUF6XucORT+AIahJzrUppLFpk76+T9ZB4YfycpNIvnzPQ45T/F+1EUR5qWnd1tdHBvC V3Yg== X-Gm-Message-State: AOAM531fFma1N8X7VIJ/Ub8T8SG/uGcoSzHD0RdosrTkb4srnv+78Ws+ TI5jRqwMM11KUvQVp3GHJ3KWcpv7dnAqkcoVY2k= X-Received: by 2002:a05:6902:705:: with SMTP id k5mr5753780ybt.67.1633237957581; Sat, 02 Oct 2021 22:12:37 -0700 (PDT) MIME-Version: 1.0 References: <20211002140247.28677-1-utkarshverma294@gmail.com> In-Reply-To: <20211002140247.28677-1-utkarshverma294@gmail.com> From: Lukas Bulwahn Date: Sun, 3 Oct 2021 07:12:26 +0200 Message-ID: Subject: Re: [PATCH v3] checkpatch: add check for continue statement in UNNECESSARY_ELSE To: Utkarsh Verma Cc: Andy Whitcroft , Joe Perches , Dwaipayan Ray , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 2, 2021 at 4:03 PM 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. Just a bit nicer wording and improving your English writing: But the same logic applies for the continue statement. > > else used after a continue statement is unnecessary. So add a test > for continue statement also. s/else/An else branch/ s/for continue statement/for the continue statement/ s/also/, too/ Other than that, all good. Great patch. > > Signed-off-by: Utkarsh Verma > --- > scripts/checkpatch.pl | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index c27d2312cfc3..0eee086d87fe 100755 > --- 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/ || > - ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ && > - defined $lines[$linenr] && > - $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) { > + if ($prevline =~ /^\+\t{$tabs,$tabs}(break|continue|return)\b/ && > + !($1 eq "return" && > + 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 $1\n" . $hereprev); > } > } > > -- > 2.25.1 >