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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 5AF0EC55178 for ; Sun, 25 Oct 2020 17:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 187D221D41 for ; Sun, 25 Oct 2020 17:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417077AbgJYR7M (ORCPT ); Sun, 25 Oct 2020 13:59:12 -0400 Received: from smtprelay0068.hostedemail.com ([216.40.44.68]:54044 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1417043AbgJYR7M (ORCPT ); Sun, 25 Oct 2020 13:59:12 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 2D00418224D61; Sun, 25 Oct 2020 17:59:11 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: nest53_241321d2726c X-Filterd-Recvd-Size: 2513 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf06.hostedemail.com (Postfix) with ESMTPA; Sun, 25 Oct 2020 17:59:10 +0000 (UTC) Message-ID: <52f88d0bb938c5063ede693a05bf64961af5a496.camel@perches.com> Subject: Re: [PATCH v5] checkpatch: extend attributes check to handle more patterns From: Joe Perches To: Dwaipayan Ray Cc: linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, lukas.bulwahn@gmail.com Date: Sun, 25 Oct 2020 10:59:09 -0700 In-Reply-To: <20201025101537.59133-1-dwaipayanray1@gmail.com> References: <20201025101537.59133-1-dwaipayanray1@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2020-10-25 at 15:45 +0530, Dwaipayan Ray wrote: > It is generally preferred that the macros from > include/linux/compiler_attributes.h are used, unless there > is a reason not to. > > checkpatch currently checks __attribute__ for each of > packed, aligned, section, printf, scanf, and weak. Other > declarations in compiler_attributes.h are not handled. > > Add a generic test to check the presence of such attributes. > Some attributes require more specific handling and are kept > separate. [] > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -6155,50 +6155,95 @@ sub process { >   } >   } >   > > -# Check for __attribute__ packed, prefer __packed > +# Check for compiler attributes >   if ($realfile !~ m@\binclude/uapi/@ && > - $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { > - WARN("PREFER_PACKED", > - "__packed is preferred over __attribute__((packed))\n" . $herecurr); > - } > + $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) { Using $rawline would also change comments and that seems wrong. Any reason to use $rawline instead of $line? [] > + if (scalar @conv_array > 0 && $conv_possible == 1) { > + my $replace = join(' ', @conv_array); > + if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "$replace is preferred over __attribute__(($attr))\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*\Q$attr\E\s*\)\s*\)/$replace/; I looks it would be useful to add $fixed[$fixlinenr] =~ s/\}\Q$replace\E/} $replace/; so there's a space added between } and any replacements.