summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/checkpatch.pl47
1 files changed, 15 insertions, 32 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7800a090e8fe..58095d9d8f34 100755
--- a/scripts/checkpatch.pl
+++ b/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)/;
}
}