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.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -241,8 +241,11 @@ our $Sparse = qr{ · 240 unmodified lines | ||
| 241 | 241 | __ref| |
| 242 | 242 | __rcu |
| 243 | 243 | }x; |
| 244 | − | |
| 245 | −our $InitAttribute = qr{__(?:mem|cpu|dev|net_|)(?:initdata|initconst|init\b)}; | |
| 244 | +our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)}; | |
| 245 | +our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)}; | |
| 246 | +our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)}; | |
| 247 | +our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)}; | |
| 248 | +our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit}; | |
| 246 | 249 | |
| 247 | 250 | # Notes to $Attribute: |
| 248 | 251 | # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check |
| @@ -3759,6 +3762,35 @@ sub process { · 3510 unmodified lines | ||
| 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 | 3794 | # prefer usleep_range over udelay |
| 3763 | 3795 | if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) { |
| 3764 | 3796 | # ignore udelay's < 10, however |