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 C8152C388F7 for ; Sun, 25 Oct 2020 08:22:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7002A22202 for ; Sun, 25 Oct 2020 08:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763126AbgJYIWT (ORCPT ); Sun, 25 Oct 2020 04:22:19 -0400 Received: from smtprelay0230.hostedemail.com ([216.40.44.230]:39056 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1735439AbgJYIWS (ORCPT ); Sun, 25 Oct 2020 04:22:18 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id F0DF418224D7E; Sun, 25 Oct 2020 08:22:16 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: drum10_180efbf27269 X-Filterd-Recvd-Size: 2240 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA; Sun, 25 Oct 2020 08:22:16 +0000 (UTC) Message-ID: Subject: Re: [PATCH v4] 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 01:22:14 -0700 In-Reply-To: <20201025065134.21737-1-dwaipayanray1@gmail.com> References: <20201025065134.21737-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 Sun, 2020-10-25 at 12:21 +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, 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. [] > Also add fixes for the generic attributes check. [] > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > + if (exists($attr_list{$curr_attr})) { > + my $new = $attr_list{$curr_attr}; > + if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "$new$params is preferred over __attribute__(($attr))\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*\Q$attr\E\s*\)\s*\)/$new$params/; Thanks. This fix would only work for the single conversions and would not work for multiple attributes like: __attribute__((aligned(4), packed)) It would be nice to be able to convert this to __aligned(4) __packed One mechanism to do that might be to: create an empty array for each attr push(@array, conversion) s/__attribute__(...)/join(' ', @array)/ if all attrs were converted.