Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp171114pxj; Wed, 26 May 2021 19:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqob06uSEOaWBJ7KkUfYpyIA97HaKIz1Eg7dV6Cu9hOKfwUfzPuXPzwXzbVT/drA/YKOkc X-Received: by 2002:a02:b890:: with SMTP id p16mr1243560jam.72.1622082793954; Wed, 26 May 2021 19:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622082793; cv=none; d=google.com; s=arc-20160816; b=EL7q4oUpiq/qXRbcNy+sqfLQM7DkC1A3mBbSG0LMxHXJCJL01ZyxpFI26U51dz4uxr VcGMbDxAImlWVVgYTiGLHWt8YnoQWIAooXJibvwfr28DbOOLGoDe020J+amfFqbaQ01Q YuY3ZWdSOHnn6/nSM7KXqeLDQCyRF/g5ISJreM0ZpsoAFDYXMApwDJMatzFTviTAK0Vj 7g8DaCBJTDvhJvClLIdG+BHTV/wunGGtYGP3yh9ZwaS4Ifhrr5uprUMn5gC0AcJd3Mgq e8pA66KGei4fmHRXVP4XcpMe5CLJohDERzuF2IWp15Jx3PGTTqtfDkiyI047lXW1awGl t5Fg== 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=JpTW2yg1Z5OhfyFhok8ov6y6DJLaEQAE9Hi7jUiRv6I=; b=CQatebK7d8RHoODpc7WjxUyCePw271A5t6P6djNGOpsj8psw67ghKYBmHX5wK16nQs CzRT1GKAcsB5NCRUYfyfdgWX3qKnE2uot7H11FoFTmRUsq//WAqSiGK5zKVKulVT3JjE jzei+LCfkf6AeEd8FYNjDpDYA0ibjrW2zz3lgsBl0Tb7JooytOv+nORDfmG+rfA0mTem 1t0YRO3d+SAUm708d58NA0JZGewBmWJMje0gKUkWj7G8+uq0y40/kFnE/2IIkTK7VF9U v6gBHuTSa62JOs0jrppXQTHZYvzL11jwsIcACUcZVZsNKkHZZmc/8W2lHfkTbexAZU5l yZGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=USpXUNsl; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si1037130ilv.33.2021.05.26.19.32.59; Wed, 26 May 2021 19:33:13 -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=@chromium.org header.s=google header.b=USpXUNsl; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234400AbhE0C2T (ORCPT + 99 others); Wed, 26 May 2021 22:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234391AbhE0C2M (ORCPT ); Wed, 26 May 2021 22:28:12 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D48D1C0613CE for ; Wed, 26 May 2021 19:26:39 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 29so2548546pgu.11 for ; Wed, 26 May 2021 19:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JpTW2yg1Z5OhfyFhok8ov6y6DJLaEQAE9Hi7jUiRv6I=; b=USpXUNslxNLCtunXjHfcvt9hHgp/8UcrlwAL7KUO34alPDZRbf5gl2X466jnO4Cmdk hcUzdoGobTLA3aVGFPvBQvYHsk5iNqw3XYsUnGbxGYotdiWiKxneCG32cLdJ6HRmz1uy RQSxltGpX1jm88PPbKyg6qGva2OfQkl/5jgB0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JpTW2yg1Z5OhfyFhok8ov6y6DJLaEQAE9Hi7jUiRv6I=; b=tZS4RnKIQIMe7HQySjAZq9LNU82HJfQb7X4bDswEZj4l/YMYde+ROcj9wT0B7L6skM PlW1M4vsldG4PJYJbHZa13/vdl0TBecmfwRZNYtEYkoiYzcqSV/wKUgmRfTEtfnwRmYZ vl/VWlFDeHFkDVmjzbD7SyYeysktcXBejGf7dUMOjSkL86sDcwPDOl25O2aWhJWg9O9J fkdrjq7GB2Il/jhFftxVifXxkcVOcJQk6w/4bQ2NgzQvfRfyAVjdLz7r7puae9/CiGA7 MLgkQ/874ZdaL2mHfP0fCQ1WxRQYrLY2niwnfkSYbfRNY7LWVYJ5po0UWLwXe9FPDpwZ cDYg== X-Gm-Message-State: AOAM531avLJK871rNPDlZMOrM88Y85pV35cbo1ZwaIpWieKJH14Y/tBF iR/0XIsshzp8bFPA0lTr1ce7Qw== X-Received: by 2002:a63:4760:: with SMTP id w32mr1514894pgk.383.1622082399429; Wed, 26 May 2021 19:26:39 -0700 (PDT) Received: from jwerner-p920.mtv.corp.google.com ([2620:15c:202:201:9021:eef6:e19b:9dd]) by smtp.gmail.com with ESMTPSA id gj21sm470703pjb.49.2021.05.26.19.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 19:26:39 -0700 (PDT) From: Julius Werner To: Andy Whitcroft , Joe Perches Cc: linux-kernel@vger.kernel.org, Julius Werner Subject: [PATCH v2 3/3] checkpatch: Ignore labels when checking indentation Date: Wed, 26 May 2021 19:26:24 -0700 Message-Id: <20210527022624.1034423-4-jwerner@chromium.org> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog In-Reply-To: <20210527022624.1034423-1-jwerner@chromium.org> References: <20210527022624.1034423-1-jwerner@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Goto labels are commonly written in the leftmost column (sometimes with one space in front), regardless of indentation level. Sometimes they're on a line of their own, but sometimes the same line is shared with a normal code statement that then starts at the expected indentation level. When checking indentation, we should check where that normal piece of code starts, not where the label starts (there's a separate INDENTED_LABEL test to check the label itself). Therefore, the line_stats() function that is used to get indentation level should treat goto labels like whitespace. The SUSPICIOUS_CODE_INDENT test also needs to explicitly ignore labels to make sure it doesn't get confused by them. Signed-off-by: Julius Werner --- scripts/checkpatch.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 624a23c05f5388..6fd16111b52cc6 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1396,8 +1396,12 @@ sub copy_spacing { sub line_stats { my ($line) = @_; - # Drop the diff line leader and expand tabs + # Drop the diff line leader $line =~ s/^.//; + + # Treat labels like whitespace when counting indentation + $line =~ s/^( ?$Ident:)/" " x length($1)/e; + $line = expand_tabs($line); # Pick the indent from the front of the line. @@ -4195,6 +4199,9 @@ sub process { # Remove any comments $s_next =~ s/$;//g; + # Remove any leading labels + $s_next =~ s/\n( ?$Ident:)/"\n" . " " x length($1)/eg; + # Skip this check for in case next statement starts with 'else' if ($s_next !~ /\belse\b/) { -- 2.29.2