From patchwork Wed Dec 16 04:44:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11976485 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 3768EC2BBCD for ; Wed, 16 Dec 2020 04:44:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DA2F223159 for ; Wed, 16 Dec 2020 04:44:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA2F223159 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6C91E6B0071; Tue, 15 Dec 2020 23:44:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 679B36B0073; Tue, 15 Dec 2020 23:44:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 590636B0074; Tue, 15 Dec 2020 23:44:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id 448336B0071 for ; Tue, 15 Dec 2020 23:44:46 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 19E211EE6 for ; Wed, 16 Dec 2020 04:44:46 +0000 (UTC) X-FDA: 77597904972.12.wine17_310688d27429 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id F295318010631 for ; Wed, 16 Dec 2020 04:44:45 +0000 (UTC) X-HE-Tag: wine17_310688d27429 X-Filterd-Recvd-Size: 4938 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 04:44:45 +0000 (UTC) Date: Tue, 15 Dec 2020 20:44:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608093884; bh=8SfWDkAeVvFBZHTIpOED2nkBDYpIPG2s3k3XI0pAxOY=; h=From:To:Subject:In-Reply-To:From; b=I7SkVSNvytecb9D2CV4KeSE4KFuWGLUEcUFVUsS+pELyjA4fhIQY4iCxmiTIt11IF KzKgBK7H7epuRAkP+MyWEOynX94CE9BPRTYcqA4jxCr/1qEwmi04tQFHBSsY2hS3KV kRsNyV3EZpgUAHFUXfJOpoQSi+xowrVWONdJdPng= From: Andrew Morton To: akpm@linux-foundation.org, dwaipayanray1@gmail.com, joe@perches.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 44/95] checkpatch: update __attribute__((section("name"))) quote removal Message-ID: <20201216044443.0bDd7RfZz%akpm@linux-foundation.org> In-Reply-To: <20201215204156.f05ec694b907845bcfab5c44@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Joe Perches Subject: checkpatch: update __attribute__((section("name"))) quote removal commit 33def8498fdd ("treewide: Convert macro and uses of __section(foo) to __section("foo")") removed the stringification of the section name and now requires quotes around the named section. Update checkpatch to not remove any quotes when suggesting conversion of __attribute__((section("name"))) to __section("name") Miscellanea: o Add section to the hash with __section replacement o Remove separate test for __attribute__((section o Remove the limitation on converting attributes containing only known, possible conversions. Any unknown attribute types are now left as-is and known types are converted and moved before __attribute__ and removed from within the __attribute__((list...)). [joe@perches.com: eliminate the separate test below the possible conversions loop] Link: https://lkml.kernel.org/r/58e9d55e933dc8fdc6af489f2ad797fa8eb13e44.camel@perches.com Link: https://lkml.kernel.org/r/c04dd1c810e8d6a68e6a632e3191ae91651c8edf.camel@perches.com Signed-off-by: Joe Perches Cc: Dwaipayan Ray Signed-off-by: Andrew Morton --- scripts/checkpatch.pl | 47 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) --- a/scripts/checkpatch.pl~checkpatch-update-__attribute__sectionname-quote-removal +++ a/scripts/checkpatch.pl @@ -6216,50 +6216,33 @@ sub process { "noreturn" => "__noreturn", "packed" => "__packed", "pure" => "__pure", + "section" => "__section", "used" => "__used" ); - my @conv_array = (); - my $conv_possible = 1; - while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) { - my $curr_attr = $1; + my $orig_attr = $1; my $params = ''; $params = $2 if defined($2); + my $curr_attr = $orig_attr; $curr_attr =~ s/^[\s_]+|[\s_]+$//g; - if (exists($attr_list{$curr_attr})) { + my $new = $attr_list{$curr_attr}; if ($curr_attr eq "format" && $params) { $params =~ /^\s*\(\s*(\w+)\s*,\s*(.*)/; - push(@conv_array, "__$1\($2"); + $new = "__$1\($2"; } else { - my $new = $attr_list{$curr_attr}; - push(@conv_array, "$new$params"); + $new = "$new$params"; + } + if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", + "Prefer $new over __attribute__(($orig_attr$params))\n" . $herecurr) && + $fix) { + my $remove = "\Q$orig_attr\E" . '\s*' . "\Q$params\E" . '(?:\s*,\s*)?'; + $fixed[$fixlinenr] =~ s/$remove//; + $fixed[$fixlinenr] =~ s/\b__attribute__/$new __attribute__/; + $fixed[$fixlinenr] =~ s/\}\Q$new\E/} $new/; + $fixed[$fixlinenr] =~ s/ __attribute__\s*\(\s*\(\s*\)\s*\)//; } - } else { - $conv_possible = 0; - last; - } - } - - 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/; - $fixed[$fixlinenr] =~ s/\}\Q$replace\E/} $replace/; - } - } - - # Check for __attribute__ section, prefer __section - if ($attr =~ /^_*section_*\s*\(\s*("[^"]*")/) { - my $old = substr($attr, $-[1], $+[1] - $-[1]); - my $new = substr($old, 1, -1); - if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", - "__section($new) is preferred over __attribute__((section($old)))\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/; } }