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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 761A3C388F9 for ; Fri, 23 Oct 2020 11:04:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2344D2192A for ; Fri, 23 Oct 2020 11:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S462747AbgJWLEq (ORCPT ); Fri, 23 Oct 2020 07:04:46 -0400 Received: from smtprelay0115.hostedemail.com ([216.40.44.115]:54974 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S462676AbgJWLEp (ORCPT ); Fri, 23 Oct 2020 07:04:45 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id C4F128B759EE; Fri, 23 Oct 2020 11:04:44 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: bag64_200105227259 X-Filterd-Recvd-Size: 3643 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf10.hostedemail.com (Postfix) with ESMTPA; Fri, 23 Oct 2020 11:04:43 +0000 (UTC) Message-ID: Subject: Re: [PATCH RFC v2] 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: Fri, 23 Oct 2020 04:04:42 -0700 In-Reply-To: <20201023094307.20820-1-dwaipayanray1@gmail.com> References: <20201023094307.20820-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: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2020-10-23 at 15:13 +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 checkpatch, no need for capitalization and non-trivially: > + my $attr_list = qr { > + __alias__| > + __aligned__$| > + __aligned__\(.*\)| > + __always_inline__| > + __assume_aligned__\(.*\)| > + __cold__| > + __const__| > + __copy__\(.*\)| > + __designated_init__| > + __externally_visible__| > + __fallthrough__| > + __gnu_inline__| > + __malloc__| > + __mode__\(.*\)| > + __no_caller_saved_registers__| > + __noclone__| > + __noinline__| > + __nonstring__| > + __noreturn__| > + __packed__| > + __pure__| > + __used__ > + }x; [] > + my %attr_replace = ( > + "__alias__" => "__alias", > + "__aligned__" => "__aligned_largest", > + "__aligned__(" => "__aligned", > + "__always_inline__" => "__always_inline", > + "__assume_aligned__(" => "__assume_aligned", > + "__cold__" => "__cold", > + "__const__" => "__const", > + "__copy__(" => "__copy", > + "__designated_init__" => "__designated_init", > + "__externally_visible__" => "__visible", > + "__fallthrough__" => "fallthrough", > + "__gnu_inline__" => "__gnu_inline", > + "__malloc__" => "__malloc", > + "__mode__(" => "__mode", > + "__no_caller_saved_registers__" => "__no_caller_saved_registers", > + "__noclone__" => "__noclone", > + "__noinline__" => "noinline", > + "__nonstring__" => "__nonstring", > + "__noreturn__" => "__noreturn", > + "__packed__" => "__packed", > + "__pure__" => "__pure", > + "__used__" => "__used" > + ); > + > + if ($attr =~/^($attr_list)/) { I would remove the __ from the entries here. And you could check using $line =~ /__attribute__\s*\(\s*($balanced_parens)\s*)/ and check for all attributes in $1 after stripping the leading and trailing parens and any leading and trailing underscores from each attribute. And you only need one hash and you should check for existence of the key rather than have multiple lists. if (exists($attributes($attr))) { > + my $old = $1; > + if ($old =~ /^(__.+__\()(.*)\)/) { > + my $new = $attr_replace{$1}; > + WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "$new($2) is preffered over __attribute__(($old))\n" . $herecurr); preferred > + } else { > + my $new = $attr_replace{$old}; > + WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "$new is preffered over __attribute__(($old))\n" . $herecurr); > + } > + }