diff options
author | Joe Perches <joe@perches.com> | 2013-11-12 15:10:10 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-13 12:09:25 +0900 |
commit | e970b8846ae4763e64be3c93dc06b4eaebf9ad63 (patch) | |
tree | 2543f6bd1d9aa24249c3d8418c0dc369434aad81 /scripts/checkpatch.pl | |
parent | 52ea85061d188031c827ecef9bce47ae93f1e52e (diff) | |
download | lwn-e970b8846ae4763e64be3c93dc06b4eaebf9ad63.tar.gz lwn-e970b8846ae4763e64be3c93dc06b4eaebf9ad63.zip |
checkpatch: add rules to check init attribute and const defects
People get this regularly wrong and it breaks the LTO builds, as it causes
a section attribute conflict.
Add --fix capability too.
Based on a patch from Andi Kleen.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 8489c35799e8..23d55bfcb5af 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -241,8 +241,11 @@ our $Sparse = qr{ __ref| __rcu }x; - -our $InitAttribute = qr{__(?:mem|cpu|dev|net_|)(?:initdata|initconst|init\b)}; +our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)}; +our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)}; +our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)}; +our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)}; +our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit}; # Notes to $Attribute: # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check @@ -3759,6 +3762,35 @@ sub process { } } +# check for $InitAttributeData (ie: __initdata) with const + if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) { + my $attr = $1; + $attr =~ /($InitAttributePrefix)(.*)/; + my $attr_prefix = $1; + my $attr_type = $2; + if (ERROR("INIT_ATTRIBUTE", + "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) && + $fix) { + $fixed[$linenr - 1] =~ + s/$InitAttributeData/${attr_prefix}initconst/; + } + } + +# check for $InitAttributeConst (ie: __initconst) without const + if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) { + my $attr = $1; + if (ERROR("INIT_ATTRIBUTE", + "Use of $attr requires a separate use of const\n" . $herecurr) && + $fix) { + my $lead = $fixed[$linenr - 1] =~ + /(^\+\s*(?:static\s+))/; + $lead = rtrim($1); + $lead = "$lead " if ($lead !~ /^\+$/); + $lead = "${lead}const "; + $fixed[$linenr - 1] =~ s/(^\+\s*(?:static\s+))/$lead/; + } + } + # prefer usleep_range over udelay if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) { # ignore udelay's < 10, however |