aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl236
-rwxr-xr-xscripts/get_maintainer.pl2
-rw-r--r--scripts/mod/file2alias.c286
-rw-r--r--scripts/package/Makefile2
4 files changed, 309 insertions, 217 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8fda3b3f7be8..e3bfcbe8a520 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -227,7 +227,7 @@ our $Inline = qr{inline|__always_inline|noinline};
227our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; 227our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
228our $Lval = qr{$Ident(?:$Member)*}; 228our $Lval = qr{$Ident(?:$Member)*};
229 229
230our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*}; 230our $Constant = qr{(?i:(?:[0-9]+|0x[0-9a-f]+)[ul]*)};
231our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; 231our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
232our $Compare = qr{<=|>=|==|!=|<|>}; 232our $Compare = qr{<=|>=|==|!=|<|>};
233our $Operators = qr{ 233our $Operators = qr{
@@ -315,7 +315,7 @@ sub build_types {
315 $NonptrType = qr{ 315 $NonptrType = qr{
316 (?:$Modifier\s+|const\s+)* 316 (?:$Modifier\s+|const\s+)*
317 (?: 317 (?:
318 (?:typeof|__typeof__)\s*\(\s*\**\s*$Ident\s*\)| 318 (?:typeof|__typeof__)\s*\([^\)]*\)|
319 (?:$typeTypedefs\b)| 319 (?:$typeTypedefs\b)|
320 (?:${all}\b) 320 (?:${all}\b)
321 ) 321 )
@@ -334,6 +334,7 @@ our $match_balanced_parentheses = qr/(\((?:[^\(\)]+|(-1))*\))/;
334 334
335our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; 335our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
336our $LvalOrFunc = qr{($Lval)\s*($match_balanced_parentheses{0,1})\s*}; 336our $LvalOrFunc = qr{($Lval)\s*($match_balanced_parentheses{0,1})\s*};
337our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)};
337 338
338sub deparenthesize { 339sub deparenthesize {
339 my ($string) = @_; 340 my ($string) = @_;
@@ -676,6 +677,10 @@ sub ctx_statement_block {
676 if ($off >= $len) { 677 if ($off >= $len) {
677 last; 678 last;
678 } 679 }
680 if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
681 $level++;
682 $type = '#';
683 }
679 } 684 }
680 $p = $c; 685 $p = $c;
681 $c = substr($blk, $off, 1); 686 $c = substr($blk, $off, 1);
@@ -738,6 +743,13 @@ sub ctx_statement_block {
738 last; 743 last;
739 } 744 }
740 } 745 }
746 # Preprocessor commands end at the newline unless escaped.
747 if ($type eq '#' && $c eq "\n" && $p ne "\\") {
748 $level--;
749 $type = '';
750 $off++;
751 last;
752 }
741 $off++; 753 $off++;
742 } 754 }
743 # We are truly at the end, so shuffle to the next line. 755 # We are truly at the end, so shuffle to the next line.
@@ -1020,7 +1032,7 @@ sub annotate_values {
1020 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') { 1032 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
1021 print "CAST($1)\n" if ($dbg_values > 1); 1033 print "CAST($1)\n" if ($dbg_values > 1);
1022 push(@av_paren_type, $type); 1034 push(@av_paren_type, $type);
1023 $type = 'C'; 1035 $type = 'c';
1024 1036
1025 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) { 1037 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
1026 print "DECLARE($1)\n" if ($dbg_values > 1); 1038 print "DECLARE($1)\n" if ($dbg_values > 1);
@@ -1212,7 +1224,9 @@ sub possible {
1212 case| 1224 case|
1213 else| 1225 else|
1214 asm|__asm__| 1226 asm|__asm__|
1215 do 1227 do|
1228 \#|
1229 \#\#|
1216 )(?:\s|$)| 1230 )(?:\s|$)|
1217 ^(?:typedef|struct|enum)\b 1231 ^(?:typedef|struct|enum)\b
1218 )}x; 1232 )}x;
@@ -1359,6 +1373,7 @@ sub process {
1359 my %suppress_ifbraces; 1373 my %suppress_ifbraces;
1360 my %suppress_whiletrailers; 1374 my %suppress_whiletrailers;
1361 my %suppress_export; 1375 my %suppress_export;
1376 my $suppress_statement = 0;
1362 1377
1363 # Pre-scan the patch sanitizing the lines. 1378 # Pre-scan the patch sanitizing the lines.
1364 # Pre-scan the patch looking for any __setup documentation. 1379 # Pre-scan the patch looking for any __setup documentation.
@@ -1468,6 +1483,7 @@ sub process {
1468 %suppress_ifbraces = (); 1483 %suppress_ifbraces = ();
1469 %suppress_whiletrailers = (); 1484 %suppress_whiletrailers = ();
1470 %suppress_export = (); 1485 %suppress_export = ();
1486 $suppress_statement = 0;
1471 next; 1487 next;
1472 1488
1473# track the line number as we move through the hunk, note that 1489# track the line number as we move through the hunk, note that
@@ -1504,9 +1520,11 @@ sub process {
1504 if ($line =~ /^diff --git.*?(\S+)$/) { 1520 if ($line =~ /^diff --git.*?(\S+)$/) {
1505 $realfile = $1; 1521 $realfile = $1;
1506 $realfile =~ s@^([^/]*)/@@; 1522 $realfile =~ s@^([^/]*)/@@;
1523 $in_commit_log = 0;
1507 } elsif ($line =~ /^\+\+\+\s+(\S+)/) { 1524 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
1508 $realfile = $1; 1525 $realfile = $1;
1509 $realfile =~ s@^([^/]*)/@@; 1526 $realfile =~ s@^([^/]*)/@@;
1527 $in_commit_log = 0;
1510 1528
1511 $p1_prefix = $1; 1529 $p1_prefix = $1;
1512 if (!$file && $tree && $p1_prefix ne '' && 1530 if (!$file && $tree && $p1_prefix ne '' &&
@@ -1546,7 +1564,8 @@ sub process {
1546 } 1564 }
1547 1565
1548# Check signature styles 1566# Check signature styles
1549 if ($line =~ /^(\s*)($signature_tags)(\s*)(.*)/) { 1567 if (!$in_header_lines &&
1568 $line =~ /^(\s*)($signature_tags)(\s*)(.*)/) {
1550 my $space_before = $1; 1569 my $space_before = $1;
1551 my $sign_off = $2; 1570 my $sign_off = $2;
1552 my $space_after = $3; 1571 my $space_after = $3;
@@ -1623,7 +1642,7 @@ sub process {
1623# Check if it's the start of a commit log 1642# Check if it's the start of a commit log
1624# (not a header line and we haven't seen the patch filename) 1643# (not a header line and we haven't seen the patch filename)
1625 if ($in_header_lines && $realfile =~ /^$/ && 1644 if ($in_header_lines && $realfile =~ /^$/ &&
1626 $rawline !~ /^(commit\b|from\b|\w+:).+$/i) { 1645 $rawline !~ /^(commit\b|from\b|[\w-]+:).+$/i) {
1627 $in_header_lines = 0; 1646 $in_header_lines = 0;
1628 $in_commit_log = 1; 1647 $in_commit_log = 1;
1629 } 1648 }
@@ -1655,19 +1674,26 @@ sub process {
1655# Only applies when adding the entry originally, after that we do not have 1674# Only applies when adding the entry originally, after that we do not have
1656# sufficient context to determine whether it is indeed long enough. 1675# sufficient context to determine whether it is indeed long enough.
1657 if ($realfile =~ /Kconfig/ && 1676 if ($realfile =~ /Kconfig/ &&
1658 $line =~ /\+\s*(?:---)?help(?:---)?$/) { 1677 $line =~ /.\s*config\s+/) {
1659 my $length = 0; 1678 my $length = 0;
1660 my $cnt = $realcnt; 1679 my $cnt = $realcnt;
1661 my $ln = $linenr + 1; 1680 my $ln = $linenr + 1;
1662 my $f; 1681 my $f;
1682 my $is_start = 0;
1663 my $is_end = 0; 1683 my $is_end = 0;
1664 while ($cnt > 0 && defined $lines[$ln - 1]) { 1684 for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
1665 $f = $lines[$ln - 1]; 1685 $f = $lines[$ln - 1];
1666 $cnt-- if ($lines[$ln - 1] !~ /^-/); 1686 $cnt-- if ($lines[$ln - 1] !~ /^-/);
1667 $is_end = $lines[$ln - 1] =~ /^\+/; 1687 $is_end = $lines[$ln - 1] =~ /^\+/;
1668 $ln++;
1669 1688
1670 next if ($f =~ /^-/); 1689 next if ($f =~ /^-/);
1690
1691 if ($lines[$ln - 1] =~ /.\s*(?:bool|tristate)\s*\"/) {
1692 $is_start = 1;
1693 } elsif ($lines[$ln - 1] =~ /.\s*(?:---)?help(?:---)?$/) {
1694 $length = -1;
1695 }
1696
1671 $f =~ s/^.//; 1697 $f =~ s/^.//;
1672 $f =~ s/#.*//; 1698 $f =~ s/#.*//;
1673 $f =~ s/^\s+//; 1699 $f =~ s/^\s+//;
@@ -1679,8 +1705,8 @@ sub process {
1679 $length++; 1705 $length++;
1680 } 1706 }
1681 WARN("CONFIG_DESCRIPTION", 1707 WARN("CONFIG_DESCRIPTION",
1682 "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4); 1708 "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_start && $is_end && $length < 4);
1683 #print "is_end<$is_end> length<$length>\n"; 1709 #print "is_start<$is_start> is_end<$is_end> length<$length>\n";
1684 } 1710 }
1685 1711
1686 if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && 1712 if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
@@ -1792,12 +1818,24 @@ sub process {
1792# Check for potential 'bare' types 1818# Check for potential 'bare' types
1793 my ($stat, $cond, $line_nr_next, $remain_next, $off_next, 1819 my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
1794 $realline_next); 1820 $realline_next);
1795 if ($realcnt && $line =~ /.\s*\S/) { 1821#print "LINE<$line>\n";
1822 if ($linenr >= $suppress_statement &&
1823 $realcnt && $line =~ /.\s*\S/) {
1796 ($stat, $cond, $line_nr_next, $remain_next, $off_next) = 1824 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
1797 ctx_statement_block($linenr, $realcnt, 0); 1825 ctx_statement_block($linenr, $realcnt, 0);
1798 $stat =~ s/\n./\n /g; 1826 $stat =~ s/\n./\n /g;
1799 $cond =~ s/\n./\n /g; 1827 $cond =~ s/\n./\n /g;
1800 1828
1829#print "linenr<$linenr> <$stat>\n";
1830 # If this statement has no statement boundaries within
1831 # it there is no point in retrying a statement scan
1832 # until we hit end of it.
1833 my $frag = $stat; $frag =~ s/;+\s*$//;
1834 if ($frag !~ /(?:{|;)/) {
1835#print "skip<$line_nr_next>\n";
1836 $suppress_statement = $line_nr_next;
1837 }
1838
1801 # Find the real next line. 1839 # Find the real next line.
1802 $realline_next = $line_nr_next; 1840 $realline_next = $line_nr_next;
1803 if (defined $realline_next && 1841 if (defined $realline_next &&
@@ -1923,6 +1961,9 @@ sub process {
1923 1961
1924# Check relative indent for conditionals and blocks. 1962# Check relative indent for conditionals and blocks.
1925 if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { 1963 if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
1964 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
1965 ctx_statement_block($linenr, $realcnt, 0)
1966 if (!defined $stat);
1926 my ($s, $c) = ($stat, $cond); 1967 my ($s, $c) = ($stat, $cond);
1927 1968
1928 substr($s, 0, length($c), ''); 1969 substr($s, 0, length($c), '');
@@ -2090,7 +2131,7 @@ sub process {
2090 # XXX(foo); 2131 # XXX(foo);
2091 # EXPORT_SYMBOL(something_foo); 2132 # EXPORT_SYMBOL(something_foo);
2092 my $name = $1; 2133 my $name = $1;
2093 if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ && 2134 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
2094 $name =~ /^${Ident}_$2/) { 2135 $name =~ /^${Ident}_$2/) {
2095#print "FOO C name<$name>\n"; 2136#print "FOO C name<$name>\n";
2096 $suppress_export{$realline_next} = 1; 2137 $suppress_export{$realline_next} = 1;
@@ -2168,8 +2209,9 @@ sub process {
2168 2209
2169# * goes on variable not on type 2210# * goes on variable not on type
2170 # (char*[ const]) 2211 # (char*[ const])
2171 if ($line =~ m{\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\)}) { 2212 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
2172 my ($from, $to) = ($1, $1); 2213 #print "AA<$1>\n";
2214 my ($from, $to) = ($2, $2);
2173 2215
2174 # Should start with a space. 2216 # Should start with a space.
2175 $to =~ s/^(\S)/ $1/; 2217 $to =~ s/^(\S)/ $1/;
@@ -2184,8 +2226,10 @@ sub process {
2184 ERROR("POINTER_LOCATION", 2226 ERROR("POINTER_LOCATION",
2185 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); 2227 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr);
2186 } 2228 }
2187 } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) { 2229 }
2188 my ($from, $to, $ident) = ($1, $1, $2); 2230 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
2231 #print "BB<$1>\n";
2232 my ($from, $to, $ident) = ($2, $2, $3);
2189 2233
2190 # Should start with a space. 2234 # Should start with a space.
2191 $to =~ s/^(\S)/ $1/; 2235 $to =~ s/^(\S)/ $1/;
@@ -2568,7 +2612,7 @@ sub process {
2568 # Flatten any parentheses 2612 # Flatten any parentheses
2569 $value =~ s/\(/ \(/g; 2613 $value =~ s/\(/ \(/g;
2570 $value =~ s/\)/\) /g; 2614 $value =~ s/\)/\) /g;
2571 while ($value =~ s/\[[^\{\}]*\]/1/ || 2615 while ($value =~ s/\[[^\[\]]*\]/1/ ||
2572 $value !~ /(?:$Ident|-?$Constant)\s* 2616 $value !~ /(?:$Ident|-?$Constant)\s*
2573 $Compare\s* 2617 $Compare\s*
2574 (?:$Ident|-?$Constant)/x && 2618 (?:$Ident|-?$Constant)/x &&
@@ -2593,28 +2637,6 @@ sub process {
2593 } 2637 }
2594 } 2638 }
2595 2639
2596# typecasts on min/max could be min_t/max_t
2597 if ($line =~ /^\+(?:.*?)\b(min|max)\s*\($Typecast{0,1}($LvalOrFunc)\s*,\s*$Typecast{0,1}($LvalOrFunc)\s*\)/) {
2598 if (defined $2 || defined $8) {
2599 my $call = $1;
2600 my $cast1 = deparenthesize($2);
2601 my $arg1 = $3;
2602 my $cast2 = deparenthesize($8);
2603 my $arg2 = $9;
2604 my $cast;
2605
2606 if ($cast1 ne "" && $cast2 ne "") {
2607 $cast = "$cast1 or $cast2";
2608 } elsif ($cast1 ne "") {
2609 $cast = $cast1;
2610 } else {
2611 $cast = $cast2;
2612 }
2613 WARN("MINMAX",
2614 "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . $herecurr);
2615 }
2616 }
2617
2618# Need a space before open parenthesis after if, while etc 2640# Need a space before open parenthesis after if, while etc
2619 if ($line=~/\b(if|while|for|switch)\(/) { 2641 if ($line=~/\b(if|while|for|switch)\(/) {
2620 ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr); 2642 ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr);
@@ -2623,6 +2645,9 @@ sub process {
2623# Check for illegal assignment in if conditional -- and check for trailing 2645# Check for illegal assignment in if conditional -- and check for trailing
2624# statements after the conditional. 2646# statements after the conditional.
2625 if ($line =~ /do\s*(?!{)/) { 2647 if ($line =~ /do\s*(?!{)/) {
2648 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
2649 ctx_statement_block($linenr, $realcnt, 0)
2650 if (!defined $stat);
2626 my ($stat_next) = ctx_statement_block($line_nr_next, 2651 my ($stat_next) = ctx_statement_block($line_nr_next,
2627 $remain_next, $off_next); 2652 $remain_next, $off_next);
2628 $stat_next =~ s/\n./\n /g; 2653 $stat_next =~ s/\n./\n /g;
@@ -2778,47 +2803,13 @@ sub process {
2778 my $cnt = $realcnt; 2803 my $cnt = $realcnt;
2779 my ($off, $dstat, $dcond, $rest); 2804 my ($off, $dstat, $dcond, $rest);
2780 my $ctx = ''; 2805 my $ctx = '';
2781
2782 my $args = defined($1);
2783
2784 # Find the end of the macro and limit our statement
2785 # search to that.
2786 while ($cnt > 0 && defined $lines[$ln - 1] &&
2787 $lines[$ln - 1] =~ /^(?:-|..*\\$)/)
2788 {
2789 $ctx .= $rawlines[$ln - 1] . "\n";
2790 $cnt-- if ($lines[$ln - 1] !~ /^-/);
2791 $ln++;
2792 }
2793 $ctx .= $rawlines[$ln - 1];
2794
2795 ($dstat, $dcond, $ln, $cnt, $off) = 2806 ($dstat, $dcond, $ln, $cnt, $off) =
2796 ctx_statement_block($linenr, $ln - $linenr + 1, 0); 2807 ctx_statement_block($linenr, $realcnt, 0);
2808 $ctx = $dstat;
2797 #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n"; 2809 #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
2798 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n"; 2810 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
2799 2811
2800 # Extract the remainder of the define (if any) and 2812 $dstat =~ s/^.\s*\#\s*define\s+$Ident(?:\([^\)]*\))?\s*//;
2801 # rip off surrounding spaces, and trailing \'s.
2802 $rest = '';
2803 while ($off != 0 || ($cnt > 0 && $rest =~ /\\\s*$/)) {
2804 #print "ADDING cnt<$cnt> $off <" . substr($lines[$ln - 1], $off) . "> rest<$rest>\n";
2805 if ($off != 0 || $lines[$ln - 1] !~ /^-/) {
2806 $rest .= substr($lines[$ln - 1], $off) . "\n";
2807 $cnt--;
2808 }
2809 $ln++;
2810 $off = 0;
2811 }
2812 $rest =~ s/\\\n.//g;
2813 $rest =~ s/^\s*//s;
2814 $rest =~ s/\s*$//s;
2815
2816 # Clean up the original statement.
2817 if ($args) {
2818 substr($dstat, 0, length($dcond), '');
2819 } else {
2820 $dstat =~ s/^.\s*\#\s*define\s+$Ident\s*//;
2821 }
2822 $dstat =~ s/$;//g; 2813 $dstat =~ s/$;//g;
2823 $dstat =~ s/\\\n.//g; 2814 $dstat =~ s/\\\n.//g;
2824 $dstat =~ s/^\s*//s; 2815 $dstat =~ s/^\s*//s;
@@ -2827,7 +2818,7 @@ sub process {
2827 # Flatten any parentheses and braces 2818 # Flatten any parentheses and braces
2828 while ($dstat =~ s/\([^\(\)]*\)/1/ || 2819 while ($dstat =~ s/\([^\(\)]*\)/1/ ||
2829 $dstat =~ s/\{[^\{\}]*\}/1/ || 2820 $dstat =~ s/\{[^\{\}]*\}/1/ ||
2830 $dstat =~ s/\[[^\{\}]*\]/1/) 2821 $dstat =~ s/\[[^\[\]]*\]/1/)
2831 { 2822 {
2832 } 2823 }
2833 2824
@@ -2844,23 +2835,32 @@ sub process {
2844 ^\"|\"$ 2835 ^\"|\"$
2845 }x; 2836 }x;
2846 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; 2837 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
2847 if ($rest ne '' && $rest ne ',') { 2838 if ($dstat ne '' &&
2848 if ($rest !~ /while\s*\(/ && 2839 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
2849 $dstat !~ /$exceptions/) 2840 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
2850 { 2841 $dstat !~ /^(?:$Ident|-?$Constant)$/ && # 10 // foo()
2851 ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", 2842 $dstat !~ /$exceptions/ &&
2852 "Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n"); 2843 $dstat !~ /^\.$Ident\s*=/ && # .foo =
2844 $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
2845 $dstat !~ /^for\s*$Constant$/ && # for (...)
2846 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
2847 $dstat !~ /^do\s*{/ && # do {...
2848 $dstat !~ /^\({/) # ({...
2849 {
2850 $ctx =~ s/\n*$//;
2851 my $herectx = $here . "\n";
2852 my $cnt = statement_rawlines($ctx);
2853
2854 for (my $n = 0; $n < $cnt; $n++) {
2855 $herectx .= raw_line($linenr, $n) . "\n";
2853 } 2856 }
2854 2857
2855 } elsif ($ctx !~ /;/) { 2858 if ($dstat =~ /;/) {
2856 if ($dstat ne '' && 2859 ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
2857 $dstat !~ /^(?:$Ident|-?$Constant)$/ && 2860 "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
2858 $dstat !~ /$exceptions/ && 2861 } else {
2859 $dstat !~ /^\.$Ident\s*=/ &&
2860 $dstat =~ /$Operators/)
2861 {
2862 ERROR("COMPLEX_MACRO", 2862 ERROR("COMPLEX_MACRO",
2863 "Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n"); 2863 "Macros with complex values should be enclosed in parenthesis\n" . "$herectx");
2864 } 2864 }
2865 } 2865 }
2866 } 2866 }
@@ -3111,6 +3111,12 @@ sub process {
3111 "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); 3111 "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
3112 } 3112 }
3113 3113
3114# Check for __attribute__ format(printf, prefer __printf
3115 if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
3116 WARN("PREFER_PRINTF",
3117 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr);
3118 }
3119
3114# check for sizeof(&) 3120# check for sizeof(&)
3115 if ($line =~ /\bsizeof\s*\(\s*\&/) { 3121 if ($line =~ /\bsizeof\s*\(\s*\&/) {
3116 WARN("SIZEOF_ADDRESS", 3122 WARN("SIZEOF_ADDRESS",
@@ -3123,6 +3129,46 @@ sub process {
3123 "Avoid line continuations in quoted strings\n" . $herecurr); 3129 "Avoid line continuations in quoted strings\n" . $herecurr);
3124 } 3130 }
3125 3131
3132# Check for misused memsets
3133 if (defined $stat &&
3134 $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
3135
3136 my $ms_addr = $2;
3137 my $ms_val = $8;
3138 my $ms_size = $14;
3139
3140 if ($ms_size =~ /^(0x|)0$/i) {
3141 ERROR("MEMSET",
3142 "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
3143 } elsif ($ms_size =~ /^(0x|)1$/i) {
3144 WARN("MEMSET",
3145 "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
3146 }
3147 }
3148
3149# typecasts on min/max could be min_t/max_t
3150 if (defined $stat &&
3151 $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
3152 if (defined $2 || defined $8) {
3153 my $call = $1;
3154 my $cast1 = deparenthesize($2);
3155 my $arg1 = $3;
3156 my $cast2 = deparenthesize($8);
3157 my $arg2 = $9;
3158 my $cast;
3159
3160 if ($cast1 ne "" && $cast2 ne "") {
3161 $cast = "$cast1 or $cast2";
3162 } elsif ($cast1 ne "") {
3163 $cast = $cast1;
3164 } else {
3165 $cast = $cast2;
3166 }
3167 WARN("MINMAX",
3168 "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
3169 }
3170 }
3171
3126# check for new externs in .c files. 3172# check for new externs in .c files.
3127 if ($realfile =~ /\.c$/ && defined $stat && 3173 if ($realfile =~ /\.c$/ && defined $stat &&
3128 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) 3174 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
@@ -3294,12 +3340,6 @@ sub process {
3294 WARN("EXPORTED_WORLD_WRITABLE", 3340 WARN("EXPORTED_WORLD_WRITABLE",
3295 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); 3341 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
3296 } 3342 }
3297
3298 # Check for memset with swapped arguments
3299 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
3300 ERROR("MEMSET",
3301 "memset size is 3rd argument, not the second.\n" . $herecurr);
3302 }
3303 } 3343 }
3304 3344
3305 # If we have no input at all, then there is nothing to report on 3345 # If we have no input at all, then there is nothing to report on
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 4594f3341051..f32a04c4c5bc 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -95,7 +95,7 @@ my %VCS_cmds_git = (
95 "execute_cmd" => \&git_execute_cmd, 95 "execute_cmd" => \&git_execute_cmd,
96 "available" => '(which("git") ne "") && (-d ".git")', 96 "available" => '(which("git") ne "") && (-d ".git")',
97 "find_signers_cmd" => 97 "find_signers_cmd" =>
98 "git log --no-color --since=\$email_git_since " . 98 "git log --no-color --follow --since=\$email_git_since " .
99 '--format="GitCommit: %H%n' . 99 '--format="GitCommit: %H%n' .
100 'GitAuthor: %an <%ae>%n' . 100 'GitAuthor: %an <%ae>%n' .
101 'GitDate: %aD%n' . 101 'GitDate: %aD%n' .
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index f936d1fa969d..c0e14b3f2306 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -28,6 +28,7 @@ typedef Elf64_Addr kernel_ulong_t;
28#endif 28#endif
29 29
30#include <ctype.h> 30#include <ctype.h>
31#include <stdbool.h>
31 32
32typedef uint32_t __u32; 33typedef uint32_t __u32;
33typedef uint16_t __u16; 34typedef uint16_t __u16;
@@ -38,6 +39,35 @@ typedef unsigned char __u8;
38 * we handle those differences explicitly below */ 39 * we handle those differences explicitly below */
39#include "../../include/linux/mod_devicetable.h" 40#include "../../include/linux/mod_devicetable.h"
40 41
42/* This array collects all instances that use the generic do_table */
43struct devtable {
44 const char *device_id; /* name of table, __mod_<name>_device_table. */
45 unsigned long id_size;
46 void *function;
47};
48
49/* We construct a table of pointers in an ELF section (pointers generally
50 * go unpadded by gcc). ld creates boundary syms for us. */
51extern struct devtable *__start___devtable[], *__stop___devtable[];
52#define ___cat(a,b) a ## b
53#define __cat(a,b) ___cat(a,b)
54
55#if __GNUC__ == 3 && __GNUC_MINOR__ < 3
56# define __used __attribute__((__unused__))
57#else
58# define __used __attribute__((__used__))
59#endif
60
61/* Add a table entry. We test function type matches while we're here. */
62#define ADD_TO_DEVTABLE(device_id, type, function) \
63 static struct devtable __cat(devtable,__LINE__) = { \
64 device_id + 0*sizeof((function)((const char *)NULL, \
65 (type *)NULL, \
66 (char *)NULL)), \
67 sizeof(type), (function) }; \
68 static struct devtable *__attribute__((section("__devtable"))) \
69 __used __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
70
41#define ADD(str, sep, cond, field) \ 71#define ADD(str, sep, cond, field) \
42do { \ 72do { \
43 strcat(str, sep); \ 73 strcat(str, sep); \
@@ -289,6 +319,7 @@ static int do_hid_entry(const char *filename,
289 319
290 return 1; 320 return 1;
291} 321}
322ADD_TO_DEVTABLE("hid", struct hid_device_id, do_hid_entry);
292 323
293/* Looks like: ieee1394:venNmoNspNverN */ 324/* Looks like: ieee1394:venNmoNspNverN */
294static int do_ieee1394_entry(const char *filename, 325static int do_ieee1394_entry(const char *filename,
@@ -313,6 +344,7 @@ static int do_ieee1394_entry(const char *filename,
313 add_wildcard(alias); 344 add_wildcard(alias);
314 return 1; 345 return 1;
315} 346}
347ADD_TO_DEVTABLE("ieee1394", struct ieee1394_device_id, do_ieee1394_entry);
316 348
317/* Looks like: pci:vNdNsvNsdNbcNscNiN. */ 349/* Looks like: pci:vNdNsvNsdNbcNscNiN. */
318static int do_pci_entry(const char *filename, 350static int do_pci_entry(const char *filename,
@@ -356,6 +388,7 @@ static int do_pci_entry(const char *filename,
356 add_wildcard(alias); 388 add_wildcard(alias);
357 return 1; 389 return 1;
358} 390}
391ADD_TO_DEVTABLE("pci", struct pci_device_id, do_pci_entry);
359 392
360/* looks like: "ccw:tNmNdtNdmN" */ 393/* looks like: "ccw:tNmNdtNdmN" */
361static int do_ccw_entry(const char *filename, 394static int do_ccw_entry(const char *filename,
@@ -379,6 +412,7 @@ static int do_ccw_entry(const char *filename,
379 add_wildcard(alias); 412 add_wildcard(alias);
380 return 1; 413 return 1;
381} 414}
415ADD_TO_DEVTABLE("ccw", struct ccw_device_id, do_ccw_entry);
382 416
383/* looks like: "ap:tN" */ 417/* looks like: "ap:tN" */
384static int do_ap_entry(const char *filename, 418static int do_ap_entry(const char *filename,
@@ -387,6 +421,7 @@ static int do_ap_entry(const char *filename,
387 sprintf(alias, "ap:t%02X*", id->dev_type); 421 sprintf(alias, "ap:t%02X*", id->dev_type);
388 return 1; 422 return 1;
389} 423}
424ADD_TO_DEVTABLE("ap", struct ap_device_id, do_ap_entry);
390 425
391/* looks like: "css:tN" */ 426/* looks like: "css:tN" */
392static int do_css_entry(const char *filename, 427static int do_css_entry(const char *filename,
@@ -395,6 +430,7 @@ static int do_css_entry(const char *filename,
395 sprintf(alias, "css:t%01X", id->type); 430 sprintf(alias, "css:t%01X", id->type);
396 return 1; 431 return 1;
397} 432}
433ADD_TO_DEVTABLE("css", struct css_device_id, do_css_entry);
398 434
399/* Looks like: "serio:tyNprNidNexN" */ 435/* Looks like: "serio:tyNprNidNexN" */
400static int do_serio_entry(const char *filename, 436static int do_serio_entry(const char *filename,
@@ -414,6 +450,7 @@ static int do_serio_entry(const char *filename,
414 add_wildcard(alias); 450 add_wildcard(alias);
415 return 1; 451 return 1;
416} 452}
453ADD_TO_DEVTABLE("serio", struct serio_device_id, do_serio_entry);
417 454
418/* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */ 455/* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */
419static int do_acpi_entry(const char *filename, 456static int do_acpi_entry(const char *filename,
@@ -422,6 +459,7 @@ static int do_acpi_entry(const char *filename,
422 sprintf(alias, "acpi*:%s:*", id->id); 459 sprintf(alias, "acpi*:%s:*", id->id);
423 return 1; 460 return 1;
424} 461}
462ADD_TO_DEVTABLE("acpi", struct acpi_device_id, do_acpi_entry);
425 463
426/* looks like: "pnp:dD" */ 464/* looks like: "pnp:dD" */
427static void do_pnp_device_entry(void *symval, unsigned long size, 465static void do_pnp_device_entry(void *symval, unsigned long size,
@@ -544,8 +582,7 @@ static int do_pcmcia_entry(const char *filename,
544 add_wildcard(alias); 582 add_wildcard(alias);
545 return 1; 583 return 1;
546} 584}
547 585ADD_TO_DEVTABLE("pcmcia", struct pcmcia_device_id, do_pcmcia_entry);
548
549 586
550static int do_of_entry (const char *filename, struct of_device_id *of, char *alias) 587static int do_of_entry (const char *filename, struct of_device_id *of, char *alias)
551{ 588{
@@ -568,6 +605,7 @@ static int do_of_entry (const char *filename, struct of_device_id *of, char *ali
568 add_wildcard(alias); 605 add_wildcard(alias);
569 return 1; 606 return 1;
570} 607}
608ADD_TO_DEVTABLE("of", struct of_device_id, do_of_entry);
571 609
572static int do_vio_entry(const char *filename, struct vio_device_id *vio, 610static int do_vio_entry(const char *filename, struct vio_device_id *vio,
573 char *alias) 611 char *alias)
@@ -585,6 +623,7 @@ static int do_vio_entry(const char *filename, struct vio_device_id *vio,
585 add_wildcard(alias); 623 add_wildcard(alias);
586 return 1; 624 return 1;
587} 625}
626ADD_TO_DEVTABLE("vio", struct vio_device_id, do_vio_entry);
588 627
589#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 628#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
590 629
@@ -640,6 +679,7 @@ static int do_input_entry(const char *filename, struct input_device_id *id,
640 do_input(alias, id->swbit, 0, INPUT_DEVICE_ID_SW_MAX); 679 do_input(alias, id->swbit, 0, INPUT_DEVICE_ID_SW_MAX);
641 return 1; 680 return 1;
642} 681}
682ADD_TO_DEVTABLE("input", struct input_device_id, do_input_entry);
643 683
644static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa, 684static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa,
645 char *alias) 685 char *alias)
@@ -650,6 +690,7 @@ static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa,
650 strcat(alias, "*"); 690 strcat(alias, "*");
651 return 1; 691 return 1;
652} 692}
693ADD_TO_DEVTABLE("eisa", struct eisa_device_id, do_eisa_entry);
653 694
654/* Looks like: parisc:tNhvNrevNsvN */ 695/* Looks like: parisc:tNhvNrevNsvN */
655static int do_parisc_entry(const char *filename, struct parisc_device_id *id, 696static int do_parisc_entry(const char *filename, struct parisc_device_id *id,
@@ -669,6 +710,7 @@ static int do_parisc_entry(const char *filename, struct parisc_device_id *id,
669 add_wildcard(alias); 710 add_wildcard(alias);
670 return 1; 711 return 1;
671} 712}
713ADD_TO_DEVTABLE("parisc", struct parisc_device_id, do_parisc_entry);
672 714
673/* Looks like: sdio:cNvNdN. */ 715/* Looks like: sdio:cNvNdN. */
674static int do_sdio_entry(const char *filename, 716static int do_sdio_entry(const char *filename,
@@ -685,6 +727,7 @@ static int do_sdio_entry(const char *filename,
685 add_wildcard(alias); 727 add_wildcard(alias);
686 return 1; 728 return 1;
687} 729}
730ADD_TO_DEVTABLE("sdio", struct sdio_device_id, do_sdio_entry);
688 731
689/* Looks like: ssb:vNidNrevN. */ 732/* Looks like: ssb:vNidNrevN. */
690static int do_ssb_entry(const char *filename, 733static int do_ssb_entry(const char *filename,
@@ -701,6 +744,7 @@ static int do_ssb_entry(const char *filename,
701 add_wildcard(alias); 744 add_wildcard(alias);
702 return 1; 745 return 1;
703} 746}
747ADD_TO_DEVTABLE("ssb", struct ssb_device_id, do_ssb_entry);
704 748
705/* Looks like: bcma:mNidNrevNclN. */ 749/* Looks like: bcma:mNidNrevNclN. */
706static int do_bcma_entry(const char *filename, 750static int do_bcma_entry(const char *filename,
@@ -719,6 +763,7 @@ static int do_bcma_entry(const char *filename,
719 add_wildcard(alias); 763 add_wildcard(alias);
720 return 1; 764 return 1;
721} 765}
766ADD_TO_DEVTABLE("bcma", struct bcma_device_id, do_bcma_entry);
722 767
723/* Looks like: virtio:dNvN */ 768/* Looks like: virtio:dNvN */
724static int do_virtio_entry(const char *filename, struct virtio_device_id *id, 769static int do_virtio_entry(const char *filename, struct virtio_device_id *id,
@@ -734,6 +779,7 @@ static int do_virtio_entry(const char *filename, struct virtio_device_id *id,
734 add_wildcard(alias); 779 add_wildcard(alias);
735 return 1; 780 return 1;
736} 781}
782ADD_TO_DEVTABLE("virtio", struct virtio_device_id, do_virtio_entry);
737 783
738/* 784/*
739 * Looks like: vmbus:guid 785 * Looks like: vmbus:guid
@@ -755,6 +801,7 @@ static int do_vmbus_entry(const char *filename, struct hv_vmbus_device_id *id,
755 801
756 return 1; 802 return 1;
757} 803}
804ADD_TO_DEVTABLE("vmbus", struct hv_vmbus_device_id, do_vmbus_entry);
758 805
759/* Looks like: i2c:S */ 806/* Looks like: i2c:S */
760static int do_i2c_entry(const char *filename, struct i2c_device_id *id, 807static int do_i2c_entry(const char *filename, struct i2c_device_id *id,
@@ -764,6 +811,7 @@ static int do_i2c_entry(const char *filename, struct i2c_device_id *id,
764 811
765 return 1; 812 return 1;
766} 813}
814ADD_TO_DEVTABLE("i2c", struct i2c_device_id, do_i2c_entry);
767 815
768/* Looks like: spi:S */ 816/* Looks like: spi:S */
769static int do_spi_entry(const char *filename, struct spi_device_id *id, 817static int do_spi_entry(const char *filename, struct spi_device_id *id,
@@ -773,6 +821,17 @@ static int do_spi_entry(const char *filename, struct spi_device_id *id,
773 821
774 return 1; 822 return 1;
775} 823}
824ADD_TO_DEVTABLE("spi", struct spi_device_id, do_spi_entry);
825
826/* Looks like: mcp:S */
827static int do_mcp_entry(const char *filename, struct mcp_device_id *id,
828 char *alias)
829{
830 sprintf(alias, MCP_MODULE_PREFIX "%s", id->name);
831
832 return 1;
833}
834ADD_TO_DEVTABLE("mcp", struct mcp_device_id, do_mcp_entry);
776 835
777static const struct dmifield { 836static const struct dmifield {
778 const char *prefix; 837 const char *prefix;
@@ -827,6 +886,7 @@ static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
827 strcat(alias, ":"); 886 strcat(alias, ":");
828 return 1; 887 return 1;
829} 888}
889ADD_TO_DEVTABLE("dmi", struct dmi_system_id, do_dmi_entry);
830 890
831static int do_platform_entry(const char *filename, 891static int do_platform_entry(const char *filename,
832 struct platform_device_id *id, char *alias) 892 struct platform_device_id *id, char *alias)
@@ -834,6 +894,7 @@ static int do_platform_entry(const char *filename,
834 sprintf(alias, PLATFORM_MODULE_PREFIX "%s", id->name); 894 sprintf(alias, PLATFORM_MODULE_PREFIX "%s", id->name);
835 return 1; 895 return 1;
836} 896}
897ADD_TO_DEVTABLE("platform", struct platform_device_id, do_platform_entry);
837 898
838static int do_mdio_entry(const char *filename, 899static int do_mdio_entry(const char *filename,
839 struct mdio_device_id *id, char *alias) 900 struct mdio_device_id *id, char *alias)
@@ -856,6 +917,7 @@ static int do_mdio_entry(const char *filename,
856 917
857 return 1; 918 return 1;
858} 919}
920ADD_TO_DEVTABLE("mdio", struct mdio_device_id, do_mdio_entry);
859 921
860/* Looks like: zorro:iN. */ 922/* Looks like: zorro:iN. */
861static int do_zorro_entry(const char *filename, struct zorro_device_id *id, 923static int do_zorro_entry(const char *filename, struct zorro_device_id *id,
@@ -866,6 +928,7 @@ static int do_zorro_entry(const char *filename, struct zorro_device_id *id,
866 ADD(alias, "i", id->id != ZORRO_WILDCARD, id->id); 928 ADD(alias, "i", id->id != ZORRO_WILDCARD, id->id);
867 return 1; 929 return 1;
868} 930}
931ADD_TO_DEVTABLE("zorro", struct zorro_device_id, do_zorro_entry);
869 932
870/* looks like: "pnp:dD" */ 933/* looks like: "pnp:dD" */
871static int do_isapnp_entry(const char *filename, 934static int do_isapnp_entry(const char *filename,
@@ -879,16 +942,84 @@ static int do_isapnp_entry(const char *filename,
879 (id->function >> 12) & 0x0f, (id->function >> 8) & 0x0f); 942 (id->function >> 12) & 0x0f, (id->function >> 8) & 0x0f);
880 return 1; 943 return 1;
881} 944}
945ADD_TO_DEVTABLE("isa", struct isapnp_device_id, do_isapnp_entry);
882 946
883/* Ignore any prefix, eg. some architectures prepend _ */ 947/*
884static inline int sym_is(const char *symbol, const char *name) 948 * Append a match expression for a single masked hex digit.
949 * outp points to a pointer to the character at which to append.
950 * *outp is updated on return to point just after the appended text,
951 * to facilitate further appending.
952 */
953static void append_nibble_mask(char **outp,
954 unsigned int nibble, unsigned int mask)
885{ 955{
886 const char *match; 956 char *p = *outp;
957 unsigned int i;
887 958
888 match = strstr(symbol, name); 959 switch (mask) {
889 if (!match) 960 case 0:
890 return 0; 961 *p++ = '?';
891 return match[strlen(name)] == '\0'; 962 break;
963
964 case 0xf:
965 p += sprintf(p, "%X", nibble);
966 break;
967
968 default:
969 /*
970 * Dumbly emit a match pattern for all possible matching
971 * digits. This could be improved in some cases using ranges,
972 * but it has the advantage of being trivially correct, and is
973 * often optimal.
974 */
975 *p++ = '[';
976 for (i = 0; i < 0x10; i++)
977 if ((i & mask) == nibble)
978 p += sprintf(p, "%X", i);
979 *p++ = ']';
980 }
981
982 /* Ensure that the string remains NUL-terminated: */
983 *p = '\0';
984
985 /* Advance the caller's end-of-string pointer: */
986 *outp = p;
987}
988
989/*
990 * looks like: "amba:dN"
991 *
992 * N is exactly 8 digits, where each is an upper-case hex digit, or
993 * a ? or [] pattern matching exactly one digit.
994 */
995static int do_amba_entry(const char *filename,
996 struct amba_id *id, char *alias)
997{
998 unsigned int digit;
999 char *p = alias;
1000
1001 if ((id->id & id->mask) != id->id)
1002 fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: "
1003 "id=0x%08X, mask=0x%08X. Please fix this driver.\n",
1004 filename, id->id, id->mask);
1005
1006 p += sprintf(alias, "amba:d");
1007 for (digit = 0; digit < 8; digit++)
1008 append_nibble_mask(&p,
1009 (id->id >> (4 * (7 - digit))) & 0xf,
1010 (id->mask >> (4 * (7 - digit))) & 0xf);
1011
1012 return 1;
1013}
1014ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry);
1015
1016/* Does namelen bytes of name exactly match the symbol? */
1017static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1018{
1019 if (namelen != strlen(symbol))
1020 return false;
1021
1022 return memcmp(name, symbol, namelen) == 0;
892} 1023}
893 1024
894static void do_table(void *symval, unsigned long size, 1025static void do_table(void *symval, unsigned long size,
@@ -921,11 +1052,25 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
921{ 1052{
922 void *symval; 1053 void *symval;
923 char *zeros = NULL; 1054 char *zeros = NULL;
1055 const char *name;
1056 unsigned int namelen;
924 1057
925 /* We're looking for a section relative symbol */ 1058 /* We're looking for a section relative symbol */
926 if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections) 1059 if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections)
927 return; 1060 return;
928 1061
1062 /* All our symbols are of form <prefix>__mod_XXX_device_table. */
1063 name = strstr(symname, "__mod_");
1064 if (!name)
1065 return;
1066 name += strlen("__mod_");
1067 namelen = strlen(name);
1068 if (namelen < strlen("_device_table"))
1069 return;
1070 if (strcmp(name + namelen - strlen("_device_table"), "_device_table"))
1071 return;
1072 namelen -= strlen("_device_table");
1073
929 /* Handle all-NULL symbols allocated into .bss */ 1074 /* Handle all-NULL symbols allocated into .bss */
930 if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) { 1075 if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) {
931 zeros = calloc(1, sym->st_size); 1076 zeros = calloc(1, sym->st_size);
@@ -936,117 +1081,24 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
936 + sym->st_value; 1081 + sym->st_value;
937 } 1082 }
938 1083
939 if (sym_is(symname, "__mod_pci_device_table")) 1084 /* First handle the "special" cases */
940 do_table(symval, sym->st_size, 1085 if (sym_is(name, namelen, "usb"))
941 sizeof(struct pci_device_id), "pci",
942 do_pci_entry, mod);
943 else if (sym_is(symname, "__mod_usb_device_table"))
944 /* special case to handle bcdDevice ranges */
945 do_usb_table(symval, sym->st_size, mod); 1086 do_usb_table(symval, sym->st_size, mod);
946 else if (sym_is(symname, "__mod_hid_device_table")) 1087 else if (sym_is(name, namelen, "pnp"))
947 do_table(symval, sym->st_size,
948 sizeof(struct hid_device_id), "hid",
949 do_hid_entry, mod);
950 else if (sym_is(symname, "__mod_ieee1394_device_table"))
951 do_table(symval, sym->st_size,
952 sizeof(struct ieee1394_device_id), "ieee1394",
953 do_ieee1394_entry, mod);
954 else if (sym_is(symname, "__mod_ccw_device_table"))
955 do_table(symval, sym->st_size,
956 sizeof(struct ccw_device_id), "ccw",
957 do_ccw_entry, mod);
958 else if (sym_is(symname, "__mod_ap_device_table"))
959 do_table(symval, sym->st_size,
960 sizeof(struct ap_device_id), "ap",
961 do_ap_entry, mod);
962 else if (sym_is(symname, "__mod_css_device_table"))
963 do_table(symval, sym->st_size,
964 sizeof(struct css_device_id), "css",
965 do_css_entry, mod);
966 else if (sym_is(symname, "__mod_serio_device_table"))
967 do_table(symval, sym->st_size,
968 sizeof(struct serio_device_id), "serio",
969 do_serio_entry, mod);
970 else if (sym_is(symname, "__mod_acpi_device_table"))
971 do_table(symval, sym->st_size,
972 sizeof(struct acpi_device_id), "acpi",
973 do_acpi_entry, mod);
974 else if (sym_is(symname, "__mod_pnp_device_table"))
975 do_pnp_device_entry(symval, sym->st_size, mod); 1088 do_pnp_device_entry(symval, sym->st_size, mod);
976 else if (sym_is(symname, "__mod_pnp_card_device_table")) 1089 else if (sym_is(name, namelen, "pnp_card"))
977 do_pnp_card_entries(symval, sym->st_size, mod); 1090 do_pnp_card_entries(symval, sym->st_size, mod);
978 else if (sym_is(symname, "__mod_pcmcia_device_table")) 1091 else {
979 do_table(symval, sym->st_size, 1092 struct devtable **p;
980 sizeof(struct pcmcia_device_id), "pcmcia", 1093
981 do_pcmcia_entry, mod); 1094 for (p = __start___devtable; p < __stop___devtable; p++) {
982 else if (sym_is(symname, "__mod_of_device_table")) 1095 if (sym_is(name, namelen, (*p)->device_id)) {
983 do_table(symval, sym->st_size, 1096 do_table(symval, sym->st_size, (*p)->id_size,
984 sizeof(struct of_device_id), "of", 1097 (*p)->device_id, (*p)->function, mod);
985 do_of_entry, mod); 1098 break;
986 else if (sym_is(symname, "__mod_vio_device_table")) 1099 }
987 do_table(symval, sym->st_size, 1100 }
988 sizeof(struct vio_device_id), "vio", 1101 }
989 do_vio_entry, mod);
990 else if (sym_is(symname, "__mod_input_device_table"))
991 do_table(symval, sym->st_size,
992 sizeof(struct input_device_id), "input",
993 do_input_entry, mod);
994 else if (sym_is(symname, "__mod_eisa_device_table"))
995 do_table(symval, sym->st_size,
996 sizeof(struct eisa_device_id), "eisa",
997 do_eisa_entry, mod);
998 else if (sym_is(symname, "__mod_parisc_device_table"))
999 do_table(symval, sym->st_size,
1000 sizeof(struct parisc_device_id), "parisc",
1001 do_parisc_entry, mod);
1002 else if (sym_is(symname, "__mod_sdio_device_table"))
1003 do_table(symval, sym->st_size,
1004 sizeof(struct sdio_device_id), "sdio",
1005 do_sdio_entry, mod);
1006 else if (sym_is(symname, "__mod_ssb_device_table"))
1007 do_table(symval, sym->st_size,
1008 sizeof(struct ssb_device_id), "ssb",
1009 do_ssb_entry, mod);
1010 else if (sym_is(symname, "__mod_bcma_device_table"))
1011 do_table(symval, sym->st_size,
1012 sizeof(struct bcma_device_id), "bcma",
1013 do_bcma_entry, mod);
1014 else if (sym_is(symname, "__mod_virtio_device_table"))
1015 do_table(symval, sym->st_size,
1016 sizeof(struct virtio_device_id), "virtio",
1017 do_virtio_entry, mod);
1018 else if (sym_is(symname, "__mod_vmbus_device_table"))
1019 do_table(symval, sym->st_size,
1020 sizeof(struct hv_vmbus_device_id), "vmbus",
1021 do_vmbus_entry, mod);
1022 else if (sym_is(symname, "__mod_i2c_device_table"))
1023 do_table(symval, sym->st_size,
1024 sizeof(struct i2c_device_id), "i2c",
1025 do_i2c_entry, mod);
1026 else if (sym_is(symname, "__mod_spi_device_table"))
1027 do_table(symval, sym->st_size,
1028 sizeof(struct spi_device_id), "spi",
1029 do_spi_entry, mod);
1030 else if (sym_is(symname, "__mod_dmi_device_table"))
1031 do_table(symval, sym->st_size,
1032 sizeof(struct dmi_system_id), "dmi",
1033 do_dmi_entry, mod);
1034 else if (sym_is(symname, "__mod_platform_device_table"))
1035 do_table(symval, sym->st_size,
1036 sizeof(struct platform_device_id), "platform",
1037 do_platform_entry, mod);
1038 else if (sym_is(symname, "__mod_mdio_device_table"))
1039 do_table(symval, sym->st_size,
1040 sizeof(struct mdio_device_id), "mdio",
1041 do_mdio_entry, mod);
1042 else if (sym_is(symname, "__mod_zorro_device_table"))
1043 do_table(symval, sym->st_size,
1044 sizeof(struct zorro_device_id), "zorro",
1045 do_zorro_entry, mod);
1046 else if (sym_is(symname, "__mod_isapnp_device_table"))
1047 do_table(symval, sym->st_size,
1048 sizeof(struct isapnp_device_id), "isa",
1049 do_isapnp_entry, mod);
1050 free(zeros); 1102 free(zeros);
1051} 1103}
1052 1104
diff --git a/scripts/package/Makefile b/scripts/package/Makefile
index bc6aa003860e..87bf08076b11 100644
--- a/scripts/package/Makefile
+++ b/scripts/package/Makefile
@@ -141,7 +141,7 @@ perf-%pkg: FORCE
141help: FORCE 141help: FORCE
142 @echo ' rpm-pkg - Build both source and binary RPM kernel packages' 142 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
143 @echo ' binrpm-pkg - Build only the binary kernel package' 143 @echo ' binrpm-pkg - Build only the binary kernel package'
144 @echo ' deb-pkg - Build the kernel as an deb package' 144 @echo ' deb-pkg - Build the kernel as a deb package'
145 @echo ' tar-pkg - Build the kernel as an uncompressed tarball' 145 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
146 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' 146 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
147 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' 147 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'