From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 916BFC4727E for ; Thu, 1 Oct 2020 17:25:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5ABA32085B for ; Thu, 1 Oct 2020 17:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732737AbgJARZI (ORCPT ); Thu, 1 Oct 2020 13:25:08 -0400 Received: from smtprelay0132.hostedemail.com ([216.40.44.132]:42024 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732096AbgJARZI (ORCPT ); Thu, 1 Oct 2020 13:25:08 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id B6BF3180A7FE4; Thu, 1 Oct 2020 17:25:06 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: fruit04_06039822719d X-Filterd-Recvd-Size: 3799 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf03.hostedemail.com (Postfix) with ESMTPA; Thu, 1 Oct 2020 17:25:05 +0000 (UTC) Message-ID: Subject: Re: [PATCH] checkpatch: fix multi-statement macro checks for while blocks. From: Joe Perches To: Dwaipayan Ray , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, lukas.bulwahn@gmail.com, Andy Whitcroft Date: Thu, 01 Oct 2020 10:25:04 -0700 In-Reply-To: <20201001171903.312021-1-dwaipayanray1@gmail.com> References: <20201001171903.312021-1-dwaipayanray1@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-10-01 at 22:49 +0530, Dwaipayan Ray wrote: > Checkpatch.pl doesn't have a check for excluding while (...) {...} > blocks from MULTISTATEMENT_MACRO_USE_DO_WHILE error. > > For example, running checkpatch.pl on the file mm/maccess.c in the > kernel generates the following error: > > ERROR: Macros with complex values should be enclosed in parentheses > +#define copy_from_kernel_nofault_loop(dst, src, len, type, err_label) \ > + while (len >= sizeof(type)) { \ > + __get_kernel_nofault(dst, src, type, err_label); \ > + dst += sizeof(type); \ > + src += sizeof(type); \ > + len -= sizeof(type); \ > + } > > The error is misleading for this case. Enclosing it in parentheses > doesn't make any sense. > > Checkpatch already has an exception list for such common macro types. > Added a new exception for while (...) {...} style blocks to the same. > > In addition, the brace flatten logic was modified by changing the > substitution characters from "1" to "1u". This was done to ensure that > macros in the form "#define foo(bar) while(bar){bar--;}" were also > correctly procecssed. > > Link: https://lore.kernel.org/linux-kernel-mentees/dc985938aa3986702815a0bd68dfca8a03c85447.camel@perches.com/ > > Suggested-by: Joe Perches > Signed-off-by: Dwaipayan Ray Thanks. Andrew, can you pick this up please? > --- > scripts/checkpatch.pl | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 9e65d21456f1..31624bbb342e 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -5299,9 +5299,9 @@ sub process { > $dstat =~ s/\s*$//s; > > # Flatten any parentheses and braces > - while ($dstat =~ s/\([^\(\)]*\)/1/ || > - $dstat =~ s/\{[^\{\}]*\}/1/ || > - $dstat =~ s/.\[[^\[\]]*\]/1/) > + while ($dstat =~ s/\([^\(\)]*\)/1u/ || > + $dstat =~ s/\{[^\{\}]*\}/1u/ || > + $dstat =~ s/.\[[^\[\]]*\]/1u/) > { > } > > @@ -5342,6 +5342,7 @@ sub process { > $dstat !~ /^\.$Ident\s*=/ && # .foo = > $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo > $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...) > + $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...} > $dstat !~ /^for\s*$Constant$/ && # for (...) > $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar() > $dstat !~ /^do\s*{/ && # do {...