Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4936339yba; Wed, 8 May 2019 05:28:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2yzTngKtC+itF/OUEhl/v5UbT3LP5RDCGkIuyaaTL/S3LrNwtwTneUiwT0cBhuH7mDhJu X-Received: by 2002:a63:e711:: with SMTP id b17mr39774156pgi.202.1557318535410; Wed, 08 May 2019 05:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557318535; cv=none; d=google.com; s=arc-20160816; b=OKs0UvJDHtmrA1GfqyNdDydPGOTkwq5H/c3KBVg/6u6588Unu/CObFyUk4c74A+C/G K6S0JnbJ8XzA9bd+eLcx3VX8YUALD3VIEH70VzT94kRkBT+NkVJpPLkBddESYp9gRUNu G9vkZBfWuI+rP8nS90wCOAiCqj/sUmRbkN6lInJygRYHEa++5ep7GTmAuJwnrr7A/qGY yb+tNftdZYVk8Dpy4DXETQjvZGnlt0/yALqPXZi1ilQAxXLeIgWH130qkK6QeDU3JNm3 2KIATH+s86VuWDR7JE4pTOcKdq68Y67WAsi477rkiO97uZY5as1ge0sL02CIf5cUlhFQ XVfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sNjqukul5u7HGksqG2zRf3b9B+HWdlpjwZ8F3uXYtMk=; b=YeoKMtZIn8OZ3rfAXfWjXQ17xSn8W0qf1snryYXkheQaf/iOP6sV2E+dFNRYwzHLUp Flzmcsd8NQuPIKp56m2qL8+dXZY0q7l3GGSMRogutjXf9kJKDPWPwOif5PBaH5p4KG5y gl11PiJzDmm1/PQ/CEQBUoTNHkxu+T9rONpijXsImqIPpmjVdHWihMBK4rj1TWGewrCj NY8/3TEEvBsJKa+ngNbyIbKzWsWF69Fq6v2AeyeH6Ik1TVwrkubOYR94BAuTBJMXi1WS Lpfb2Lr/K1GXEviCKF6u/0MPQWmW6fGb+wjdWVbCfVtfCxhNY0at0CqvZjycC0rMWL7X vbMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UompOFt4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id o5si23876194plh.288.2019.05.08.05.28.39; Wed, 08 May 2019 05:28:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UompOFt4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728570AbfEHM1n (ORCPT + 99 others); Wed, 8 May 2019 08:27:43 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37387 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728551AbfEHM1m (ORCPT ); Wed, 8 May 2019 08:27:42 -0400 Received: by mail-wm1-f66.google.com with SMTP id y5so3028458wma.2 for ; Wed, 08 May 2019 05:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sNjqukul5u7HGksqG2zRf3b9B+HWdlpjwZ8F3uXYtMk=; b=UompOFt4jFZuue0a6Pd4JJGnhksRvGJpysjG3VONr6phJZs/eX80CmvcqIck30xoDX jjc0Zk+1lZwfBmZddBuuqOsb/KvDxD2sAKFZEOTtV2JNb9qjEvt29Hmha45O+aHUYcWf /FWp23bODd+AiisI4Xn35ItlvcgI5QZS5+QDz4x7q8BJgGQhOQm2wq8PR/r6br56T6ik Sn+4RjksEOjN9nffopWr+bLcQIVfBGJMiTsy9EevMm4CtGx2LzSmlsUsdcPO7ZVnPslW qevuIZof3Fo9WUHVTXpIsK/NYN/0gtrZk1uEOGOBxeUbGco+o6r6MVLhglemNXwoLFzb bFRA== 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=sNjqukul5u7HGksqG2zRf3b9B+HWdlpjwZ8F3uXYtMk=; b=l4HcEb4xtbQsOJZevjK5S4L2r2fcQgT2aN1LewD2ch7rQN0MoagCMiGT45fFgd+gF0 2P4s6eLWgO4kXxMNBVuUWI6jm5Yvq1HtOJkW8JQ310vWY0m7hGCwseRl2/rEKQRqIiXm 6dipLb7/vjpA17gcFLQN0sGFN5ji091VO51upAe4FuZRiioVyvJ1US2J3BgtRWReRced pbsA+6v+aFwLxvAuXuaVEW+7a/o5CyFyeB3ZAJB4i4Ui57tCxmbhxJ47ZlSwvGams67k RH9hYxRTvJ/Sc6sO544Obh2hxKsEi8g9hujcW/ye9eKPj0ZeGT2RR/mZNkigMEg7rLIi KUFQ== X-Gm-Message-State: APjAAAXUJpmkkGrpR2bzyo3l5dBPiLEm9qPD9G0T/Yk99k8Cf+F6mV3W Ai2ovhqINb+vcn1s4KGpgSQ= X-Received: by 2002:a1c:7518:: with SMTP id o24mr2897048wmc.42.1557318458700; Wed, 08 May 2019 05:27:38 -0700 (PDT) Received: from localhost.localdomain ([2a01:e34:edb8:72e0:1074:1d8f:2a88:25e6]) by smtp.gmail.com with ESMTPSA id s124sm3217737wmf.42.2019.05.08.05.27.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 May 2019 05:27:37 -0700 (PDT) From: Antonio Borneo To: Joe Perches , Andy Whitcroft Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/4] checkpatch: replace magic value for TAB size Date: Wed, 8 May 2019 14:27:21 +0200 Message-Id: <20190508122721.7513-4-borneo.antonio@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190508122721.7513-1-borneo.antonio@gmail.com> References: <20190508122721.7513-1-borneo.antonio@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The size of 8 characters used for both TAB and indentation is embedded as magic value allover the checkpatch script, and this makes the script less readable. Replace the magic value 8 with the perl variable "$tabsize". From the context of the code it's clear if it is used for indentation or tabulation, so no need to use two separate variables. As side benefit of this change, it makes easy to replace the TAB size when this script is used by other projects with different requirements in their coding style (e.g. OpenOCD [1] requires TAB size of 4 characters [2]). In these cases the script will be probably modified and adapted, so there is no need (at least for the moment) to expose this setting on the script's command line. [1] http://openocd.org/ [2] http://openocd.org/doc/doxygen/html/stylec.html#styleformat Signed-off-by: Antonio Borneo Signed-off-by: Erik Ahlén Signed-off-by: Spencer Oliver --- scripts/checkpatch.pl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 373ad345f732..3c8115600516 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -62,6 +62,7 @@ my $conststructsfile = "$D/const_structs.checkpatch"; my $typedefsfile = ""; my $color = "auto"; my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE +my $tabsize = 8; sub help { my ($exitcode) = @_; @@ -1211,7 +1212,7 @@ sub expand_tabs { if ($c eq "\t") { $res .= ' '; $n++; - for (; ($n % 8) != 0; $n++) { + for (; ($n % $tabsize) != 0; $n++) { $res .= ' '; } next; @@ -2224,7 +2225,7 @@ sub string_find_replace { sub tabify { my ($leading) = @_; - my $source_indent = 8; + my $source_indent = $tabsize; my $max_spaces_before_tab = $source_indent - 1; my $spaces_to_tab = " " x $source_indent; @@ -3153,7 +3154,7 @@ sub process { next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/); # at the beginning of a line any tabs must come first and anything -# more than 8 must use tabs. +# more than $tabsize must use tabs. if ($rawline =~ /^\+\s* \t\s*\S/ || $rawline =~ /^\+\s* \s*/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; @@ -3172,7 +3173,7 @@ sub process { "please, no space before tabs\n" . $herevet) && $fix) { while ($fixed[$fixlinenr] =~ - s/(^\+.*) {8,8}\t/$1\t\t/) {} + s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {} while ($fixed[$fixlinenr] =~ s/(^\+.*) +\t/$1\t/) {} } @@ -3194,11 +3195,11 @@ sub process { if ($perl_version_ok && $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) { my $indent = length($1); - if ($indent % 8) { + if ($indent % $tabsize) { if (WARN("TABSTOP", "Statements should start on a tabstop\n" . $herecurr) && $fix) { - $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/8)@e; + $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e; } } } @@ -3216,8 +3217,8 @@ sub process { my $newindent = $2; my $goodtabindent = $oldindent . - "\t" x ($pos / 8) . - " " x ($pos % 8); + "\t" x ($pos / $tabsize) . + " " x ($pos % $tabsize); my $goodspaceindent = $oldindent . " " x $pos; if ($newindent ne $goodtabindent && @@ -3688,11 +3689,11 @@ sub process { #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n"; if ($check && $s ne '' && - (($sindent % 8) != 0 || + (($sindent % $tabsize) != 0 || ($sindent < $indent) || ($sindent == $indent && ($s !~ /^\s*(?:\}|\{|else\b)/)) || - ($sindent > $indent + 8))) { + ($sindent > $indent + $tabsize))) { WARN("SUSPECT_CODE_INDENT", "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); } -- 2.21.0