aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2013-11-12 18:10:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-12 22:09:25 -0500
commite970b8846ae4763e64be3c93dc06b4eaebf9ad63 (patch)
tree2543f6bd1d9aa24249c3d8418c0dc369434aad81
parent52ea85061d188031c827ecef9bce47ae93f1e52e (diff)
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>
-rwxr-xr-xscripts/checkpatch.pl36
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{
241 __ref| 241 __ref|
242 __rcu 242 __rcu
243 }x; 243 }x;
244 244our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
245our $InitAttribute = qr{__(?:mem|cpu|dev|net_|)(?:initdata|initconst|init\b)}; 245our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
246our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
247our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
248our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
246 249
247# Notes to $Attribute: 250# Notes to $Attribute:
248# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check 251# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
@@ -3759,6 +3762,35 @@ sub process {
3759 } 3762 }
3760 } 3763 }
3761 3764
3765# check for $InitAttributeData (ie: __initdata) with const
3766 if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
3767 my $attr = $1;
3768 $attr =~ /($InitAttributePrefix)(.*)/;
3769 my $attr_prefix = $1;
3770 my $attr_type = $2;
3771 if (ERROR("INIT_ATTRIBUTE",
3772 "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
3773 $fix) {
3774 $fixed[$linenr - 1] =~
3775 s/$InitAttributeData/${attr_prefix}initconst/;
3776 }
3777 }
3778
3779# check for $InitAttributeConst (ie: __initconst) without const
3780 if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
3781 my $attr = $1;
3782 if (ERROR("INIT_ATTRIBUTE",
3783 "Use of $attr requires a separate use of const\n" . $herecurr) &&
3784 $fix) {
3785 my $lead = $fixed[$linenr - 1] =~
3786 /(^\+\s*(?:static\s+))/;
3787 $lead = rtrim($1);
3788 $lead = "$lead " if ($lead !~ /^\+$/);
3789 $lead = "${lead}const ";
3790 $fixed[$linenr - 1] =~ s/(^\+\s*(?:static\s+))/$lead/;
3791 }
3792 }
3793
3762# prefer usleep_range over udelay 3794# prefer usleep_range over udelay
3763 if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) { 3795 if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
3764 # ignore udelay's < 10, however 3796 # ignore udelay's < 10, however