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=-6.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 37652C4727C for ; Thu, 1 Oct 2020 13:42:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 035F6207F7 for ; Thu, 1 Oct 2020 13:42:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732169AbgJANmh (ORCPT ); Thu, 1 Oct 2020 09:42:37 -0400 Received: from smtprelay0235.hostedemail.com ([216.40.44.235]:34314 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731993AbgJANmg (ORCPT ); Thu, 1 Oct 2020 09:42:36 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id 30C70100E7B49; Thu, 1 Oct 2020 13:42:35 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: power08_61089732719b X-Filterd-Recvd-Size: 4147 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA; Thu, 1 Oct 2020 13:42:34 +0000 (UTC) Message-ID: Subject: Re: [PATCH RFC] checkpatch: fix multi-statement macro checks From: Joe Perches To: Dwaipayan Ray Cc: linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Lukas Bulwahn Date: Thu, 01 Oct 2020 06:42:32 -0700 In-Reply-To: References: <20201001103314.136645-1-dwaipayanray1@gmail.com> <8e110121c89414ab1601071868dbcf410195a209.camel@perches.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 18:57 +0530, Dwaipayan Ray wrote: > On Thu, Oct 1, 2020 at 6:47 PM Joe Perches wrote: > > On Thu, 2020-10-01 at 16:03 +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/access.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 parantheses > > > doesn't make any sense. > > > > OK > > > > > Checkpatch already has an exception list for such common macro types. > > > Added a new exception for while (...) {...} style blocks to the same. > > > This effectively fixed the wrong error message. > > [] > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > [] > > > @@ -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 (...) {...} Note the \s* ^ > > Did you try to output $dstat for some matching cases? > > What was the $dstat value for the cases you tried? > > > > > Hi, > I did check $dstat values. > > For example on file mm/maccess.c, there were two such macros: > > Case 1: > > $ctx: > +#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); \ > + } > > $dstat: > while 1 1 And perhaps this test should use \s+ instead. What is $dstat with a #define like: #define foo(bar,baz)while(bar){bar--;baz++;} (no spaces anywhere bot the required one after define > Case 2: > > $ctx: > +#define copy_to_kernel_nofault_loop(dst, src, len, type, err_label) \ > + while (len >= sizeof(type)) { \ > + __put_kernel_nofault(dst, src, type, err_label); \ > + dst += sizeof(type); \ > + src += sizeof(type); \ > + len -= sizeof(type); \ > + } > > $dstat: > while 1 1 > > > Thanks, > Dwaipayan.