Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1574438pxb; Fri, 1 Oct 2021 13:50:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwRoRcT62p8CGtVQmSm6O26u286nLT140unvYJQjl7gHaW4aGYYH9NS0Vq2HdbRf3Keq2P X-Received: by 2002:a63:1d58:: with SMTP id d24mr100451pgm.316.1633121424128; Fri, 01 Oct 2021 13:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633121424; cv=none; d=google.com; s=arc-20160816; b=GQhyYTzEFbDdG/3DapiKXZ70iU7H1WMvmebnV+aimENm5DmlJPFhUED4AZ+DD2JYmR LQpZIiwMEV9PmXyx2DV9sLn8cubxv25NETAqr6Mv7LgQiK4L+x4elgHbF3YSkqqQbt4J /WouF9lQG0XC6WCYI4ljw0pgw5gFx0cvigKxgbMrRuCu5r2CsRZY5XJx7ZKTVyWr5H0C fIHCE1cVG1So12nF8JqkeN1oGt4rfdTE3FBJoazW9gLgA1xWM/35NfROxIFAA3gMQrp2 g5TL09AIovWJEIstlKipBGM2kYx7uqvFnwyS1wD+7BMR7XLXKRrfF1lcBh6aPQmvR9dh hztw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CM75l1KfmJgyjxqnyhwFA+NjvDgZwcBD+dHHoEi1ePM=; b=v/34NOXWhaWomnRMSaE3NwJFdJB+wTgdz3rHVLXUoTgYc5kOK7XO5wIsNUKnbSzz1O dfHwstJY6MADggGTWq34ju5BL5AiPpqtAHB7z301yI0r1qHF8cdOcPWWFUUWJ8ajtiCH +rIdt14TywMBijuFqc10gmVsSad8Ol5CRvxxv66Xw/V45qEWB0huQcGEyepsgGB/XBn/ AwqXBQrN+sWn1ETxmZiO9OE5KPm7EPorSDzG0I01dsgtorJ/wkhhatRAwCPyYl7wMMs9 ve9RgJUytNA2Jsc+3ncXM8eCr0aJLMcSORi2N5RLAiQccCnpOhevSbMehwxE3dpifuVQ jseQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=d90nkWX2; 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 k11si8902180pls.308.2021.10.01.13.50.11; Fri, 01 Oct 2021 13:50:24 -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=d90nkWX2; 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 S230110AbhJAUtP (ORCPT + 99 others); Fri, 1 Oct 2021 16:49:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbhJAUtO (ORCPT ); Fri, 1 Oct 2021 16:49:14 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40588C061775 for ; Fri, 1 Oct 2021 13:47:30 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 75so10486589pga.3 for ; Fri, 01 Oct 2021 13:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CM75l1KfmJgyjxqnyhwFA+NjvDgZwcBD+dHHoEi1ePM=; b=d90nkWX271k0CCQ2LTMWKAYScJ4vQCjCbwa0ymrK43hSqZeTZ7oI2idmY9G10VUwYT xp+JpXAqJIpWkPLkcgrEPqZVqGhKnfBPsVDCNP++UFV+JprM1BgunKdFDtWtz85whA0t f4SQkLVN/W6P0x0QmkRlFV6tXNKWvRUANWyEFwl3W2EqeBL7kEJT6WoJ5RM7C4KVaRv1 wsfz8rAoC68g/xjeeozngNbMEgqQ6LoMAL1HbWu+7EKremzt8wMy3r5OFzMZEO5wFgxE YQGb1GOVQnG/0YFx9ygXxrYJPk2qQAOyXHe0enNrFu2eT+Fx5/lUkcVeYzchNog++bk4 khOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CM75l1KfmJgyjxqnyhwFA+NjvDgZwcBD+dHHoEi1ePM=; b=xEP5+ldXe51pvy/g6fqQY7SkM2F5fE8P9kwxwpqSUC3cDE5nns8MmQGnljftuOt3mp qKR7TVvEn99buwwk3JZrgyRFbBdNlAiSpcgo9yJaM4goF1YFEw6wZnnff8/FIj0OFiVQ gN9XrP4y+I936xM+GJECgAem2Q1VVzByPrs+rkMuJBLoaWYZsaIlM984ZtBF/JpXgKKF crk5aRw8YEPGTmboB7jyusRa4ZEXBD9ctKs0tflTdwe+oTk19MWCYS0DlJXj1SSXmg5a g/Sa/s89HOfexaa59Iesr02rJXmD7QNkyexL5GqMtCm8oRI1iZvjNSOtp0eg284JpKWz veZQ== X-Gm-Message-State: AOAM532odz+Au8QmqhJxduAyYoQsPW3lyhktBEISulmH0dimJupmumo6 bXXrEoi4IEbFMVLZ9fEy69M= X-Received: by 2002:a05:6a00:b47:b0:43d:cac0:cbe with SMTP id p7-20020a056a000b4700b0043dcac00cbemr13102367pfo.79.1633121249611; Fri, 01 Oct 2021 13:47:29 -0700 (PDT) Received: from localhost.localdomain ([2405:201:6006:a148:3571:e0d6:948:af69]) by smtp.googlemail.com with ESMTPSA id z25sm7030934pfj.199.2021.10.01.13.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 13:47:28 -0700 (PDT) From: Utkarsh Verma To: Andy Whitcroft , Joe Perches Cc: Dwaipayan Ray , Lukas Bulwahn , linux-kernel@vger.kernel.org, Utkarsh Verma Subject: [PATCH v2] checkpatch: add check for continue statement in UNNECESSARY_ELSE Date: Sat, 2 Oct 2021 02:17:05 +0530 Message-Id: <20211001204705.7448-1-utkarshverma294@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <91569a87ac55da392fa894e8ad55292b98c558f3.camel@perches.com> References: <91569a87ac55da392fa894e8ad55292b98c558f3.camel@perches.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Utkarsh Verma --- scripts/checkpatch.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c27d2312cfc3..edbb74dda5cb 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/ || + 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); } } -- 2.25.1