Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756931AbdLPP4J (ORCPT ); Sat, 16 Dec 2017 10:56:09 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49992 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752746AbdLPP4I (ORCPT ); Sat, 16 Dec 2017 10:56:08 -0500 Message-ID: <1513439756.31439.5.camel@oracle.com> Subject: Re: [PATCH v2 3/5] checkpatch: Improve --fix-inplace for TABSTOP From: Knut Omang To: Joe Perches , linux-kernel@vger.kernel.org Cc: Andy Whitcroft , Andrew Morton , Dan Carpenter Date: Sat, 16 Dec 2017 16:55:56 +0100 In-Reply-To: <1513437230.4647.25.camel@perches.com> References: <054ce1000f13fb321b84ac474957a759633e5a9d.1513430008.git-series.knut.omang@oracle.com> <1513437230.4647.25.camel@perches.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.24.6 (3.24.6-1.fc26) Mime-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8747 signatures=668649 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712160239 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vBGFuDcL017651 Content-Length: 2639 Lines: 75 On Sat, 2017-12-16 at 07:13 -0800, Joe Perches wrote: > On Sat, 2017-12-16 at 15:42 +0100, Knut Omang wrote: > > If the --fix-inplace option for TABSTOP encounters a sitation with several > > spaces (but less than 8) at the end of an indentation, it will assume that there > > are extra indentation and align back to the nearest tabstop instead of the next. > > > > This might go undetected in a "full" checkpatch --fix-inplace run, as this > > potential new error will be handled by SUSPECT_CODE_INDENT further down in the > > script. The code for TABSTOP have limited "knowledge" of the previous line. > > Adding complexity when it is taken care of later anyway is maybe > unnecessary/undesired. > > As a simple heuristics just use a "natural" rounding algorithm and round > > up for 4 spaces or more. > > > > There's an example in line 108 in net/rds/ib_recv.c with indentation TAB + 7 > > spaces where the correct would have been an additional TAB. With only TABSTOP > > enabled, checkpatch will fix this to a single TAB, which is visually worse IMO. > > > > Reported-by: Håkon Bugge > > Signed-off-by: Knut Omang > > Reviewed-by: Håkon Bugge > > Well written commit log description, thanks but > I'm not sure that's actually better overall. > > It's not possible to know if the appropriate thing > to do is to add a tab or remove spaces. > > This may get it wrong about as often as the current > code gets it right. > > Last I checked 6 months or so ago, there were ~8000 > TABSTOP warnings in the kernel tree. > > Most of those still seem valid and moving additional > places to the right is sometimes incorrect too. > > It seems most common when there are 3 or 4 spaces > used as indent level indentation instead of tabs. I see your point here, definitely - more detailed statistics needed... > Dunno. Let me take this out of the set in the next version as it is really a separate issue. > Anyone else have an opinion? Thanks, Knut > > > --- > > scripts/checkpatch.pl | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > index 040aa79..febe010 100755 > > --- a/scripts/checkpatch.pl > > +++ b/scripts/checkpatch.pl > > @@ -2989,7 +2989,7 @@ sub process { > > 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+4)/8)@e; > > } > > } > > }