aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 20:12:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 20:12:13 -0400
commit7f0ef0267e20d62d45d527911a993b1e998f4968 (patch)
treede51abc7da5903f59d83e23937f22420164c9477 /scripts
parent862f0012549110d6f2586bf54b52ed4540cbff3a (diff)
parent9307c29524502c21f0e8a6d96d850b2f5bc0bd9a (diff)
Merge branch 'akpm' (updates from Andrew Morton)
Merge first patch-bomb from Andrew Morton: - various misc bits - I'm been patchmonkeying ocfs2 for a while, as Joel and Mark have been distracted. There has been quite a bit of activity. - About half the MM queue - Some backlight bits - Various lib/ updates - checkpatch updates - zillions more little rtc patches - ptrace - signals - exec - procfs - rapidio - nbd - aoe - pps - memstick - tools/testing/selftests updates * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (445 commits) tools/testing/selftests: don't assume the x bit is set on scripts selftests: add .gitignore for kcmp selftests: fix clean target in kcmp Makefile selftests: add .gitignore for vm selftests: add hugetlbfstest self-test: fix make clean selftests: exit 1 on failure kernel/resource.c: remove the unneeded assignment in function __find_resource aio: fix wrong comment in aio_complete() drivers/w1/slaves/w1_ds2408.c: add magic sequence to disable P0 test mode drivers/memstick/host/r592.c: convert to module_pci_driver drivers/memstick/host/jmb38x_ms: convert to module_pci_driver pps-gpio: add device-tree binding and support drivers/pps/clients/pps-gpio.c: convert to module_platform_driver drivers/pps/clients/pps-gpio.c: convert to devm_* helpers drivers/parport/share.c: use kzalloc Documentation/accounting/getdelays.c: avoid strncpy in accounting tool aoe: update internal version number to v83 aoe: update copyright date aoe: perform I/O completions in parallel ...
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl636
-rw-r--r--scripts/mod/devicetable-offsets.c6
-rw-r--r--scripts/mod/file2alias.c20
3 files changed, 551 insertions, 111 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b954de58304f..6afcd1239ca5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -27,9 +27,11 @@ my $summary = 1;
27my $mailback = 0; 27my $mailback = 0;
28my $summary_file = 0; 28my $summary_file = 0;
29my $show_types = 0; 29my $show_types = 0;
30my $fix = 0;
30my $root; 31my $root;
31my %debug; 32my %debug;
32my %ignore_type = (); 33my %ignore_type = ();
34my %camelcase = ();
33my @ignore = (); 35my @ignore = ();
34my $help = 0; 36my $help = 0;
35my $configuration_file = ".checkpatch.conf"; 37my $configuration_file = ".checkpatch.conf";
@@ -63,6 +65,11 @@ Options:
63 is all off) 65 is all off)
64 --test-only=WORD report only warnings/errors containing WORD 66 --test-only=WORD report only warnings/errors containing WORD
65 literally 67 literally
68 --fix EXPERIMENTAL - may create horrible results
69 If correctable single-line errors exist, create
70 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
71 with potential errors corrected to the preferred
72 checkpatch style
66 -h, --help, --version display this help and exit 73 -h, --help, --version display this help and exit
67 74
68When FILE is - read standard input. 75When FILE is - read standard input.
@@ -114,7 +121,7 @@ GetOptions(
114 'summary!' => \$summary, 121 'summary!' => \$summary,
115 'mailback!' => \$mailback, 122 'mailback!' => \$mailback,
116 'summary-file!' => \$summary_file, 123 'summary-file!' => \$summary_file,
117 124 'fix!' => \$fix,
118 'debug=s' => \%debug, 125 'debug=s' => \%debug,
119 'test-only=s' => \$tst_only, 126 'test-only=s' => \$tst_only,
120 'h|help' => \$help, 127 'h|help' => \$help,
@@ -230,17 +237,22 @@ our $Inline = qr{inline|__always_inline|noinline};
230our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; 237our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
231our $Lval = qr{$Ident(?:$Member)*}; 238our $Lval = qr{$Ident(?:$Member)*};
232 239
240our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u};
241our $Binary = qr{(?i)0b[01]+$Int_type?};
242our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
243our $Int = qr{[0-9]+$Int_type?};
233our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; 244our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
234our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; 245our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
235our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; 246our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
236our $Float = qr{$Float_hex|$Float_dec|$Float_int}; 247our $Float = qr{$Float_hex|$Float_dec|$Float_int};
237our $Constant = qr{$Float|(?i)(?:0x[0-9a-f]+|[0-9]+)[ul]*}; 248our $Constant = qr{$Float|$Binary|$Hex|$Int};
238our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; 249our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
239our $Compare = qr{<=|>=|==|!=|<|>}; 250our $Compare = qr{<=|>=|==|!=|<|>};
251our $Arithmetic = qr{\+|-|\*|\/|%};
240our $Operators = qr{ 252our $Operators = qr{
241 <=|>=|==|!=| 253 <=|>=|==|!=|
242 =>|->|<<|>>|<|>|!|~| 254 =>|->|<<|>>|<|>|!|~|
243 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% 255 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
244 }x; 256 }x;
245 257
246our $NonptrType; 258our $NonptrType;
@@ -269,7 +281,7 @@ our $typeTypedefs = qr{(?x:
269 281
270our $logFunctions = qr{(?x: 282our $logFunctions = qr{(?x:
271 printk(?:_ratelimited|_once|)| 283 printk(?:_ratelimited|_once|)|
272 [a-z0-9]+_(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)| 284 (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
273 WARN(?:_RATELIMIT|_ONCE|)| 285 WARN(?:_RATELIMIT|_ONCE|)|
274 panic| 286 panic|
275 MODULE_[A-Z_]+ 287 MODULE_[A-Z_]+
@@ -338,7 +350,6 @@ sub build_types {
338} 350}
339build_types(); 351build_types();
340 352
341
342our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; 353our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
343 354
344# Using $balanced_parens, $LvalOrFunc, or $FuncArg 355# Using $balanced_parens, $LvalOrFunc, or $FuncArg
@@ -358,10 +369,79 @@ sub deparenthesize {
358 return $string; 369 return $string;
359} 370}
360 371
372sub seed_camelcase_file {
373 my ($file) = @_;
374
375 return if (!(-f $file));
376
377 local $/;
378
379 open(my $include_file, '<', "$file")
380 or warn "$P: Can't read '$file' $!\n";
381 my $text = <$include_file>;
382 close($include_file);
383
384 my @lines = split('\n', $text);
385
386 foreach my $line (@lines) {
387 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
388 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
389 $camelcase{$1} = 1;
390 }
391 elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*\(/) {
392 $camelcase{$1} = 1;
393 }
394 }
395}
396
397my $camelcase_seeded = 0;
398sub seed_camelcase_includes {
399 return if ($camelcase_seeded);
400
401 my $files;
402 my $camelcase_git_file = "";
403
404 if (-d ".git") {
405 my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
406 chomp $git_last_include_commit;
407 $camelcase_git_file = ".checkpatch-camelcase.$git_last_include_commit";
408 if (-f $camelcase_git_file) {
409 open(my $camelcase_file, '<', "$camelcase_git_file")
410 or warn "$P: Can't read '$camelcase_git_file' $!\n";
411 while (<$camelcase_file>) {
412 chomp;
413 $camelcase{$_} = 1;
414 }
415 close($camelcase_file);
416
417 return;
418 }
419 $files = `git ls-files include`;
420 } else {
421 $files = `find $root/include -name "*.h"`;
422 }
423 my @include_files = split('\n', $files);
424 foreach my $file (@include_files) {
425 seed_camelcase_file($file);
426 }
427 $camelcase_seeded = 1;
428
429 if ($camelcase_git_file ne "") {
430 unlink glob ".checkpatch-camelcase.*";
431 open(my $camelcase_file, '>', "$camelcase_git_file")
432 or warn "$P: Can't write '$camelcase_git_file' $!\n";
433 foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
434 print $camelcase_file ("$_\n");
435 }
436 close($camelcase_file);
437 }
438}
439
361$chk_signoff = 0 if ($file); 440$chk_signoff = 0 if ($file);
362 441
363my @rawlines = (); 442my @rawlines = ();
364my @lines = (); 443my @lines = ();
444my @fixed = ();
365my $vname; 445my $vname;
366for my $filename (@ARGV) { 446for my $filename (@ARGV) {
367 my $FILE; 447 my $FILE;
@@ -389,6 +469,7 @@ for my $filename (@ARGV) {
389 } 469 }
390 @rawlines = (); 470 @rawlines = ();
391 @lines = (); 471 @lines = ();
472 @fixed = ();
392} 473}
393 474
394exit($exit); 475exit($exit);
@@ -429,7 +510,7 @@ sub parse_email {
429 $comment = $2 if defined $2; 510 $comment = $2 if defined $2;
430 $formatted_email =~ s/$address.*$//; 511 $formatted_email =~ s/$address.*$//;
431 $name = $formatted_email; 512 $name = $formatted_email;
432 $name =~ s/^\s+|\s+$//g; 513 $name = trim($name);
433 $name =~ s/^\"|\"$//g; 514 $name =~ s/^\"|\"$//g;
434 # If there's a name left after stripping spaces and 515 # If there's a name left after stripping spaces and
435 # leading quotes, and the address doesn't have both 516 # leading quotes, and the address doesn't have both
@@ -444,9 +525,9 @@ sub parse_email {
444 } 525 }
445 } 526 }
446 527
447 $name =~ s/^\s+|\s+$//g; 528 $name = trim($name);
448 $name =~ s/^\"|\"$//g; 529 $name =~ s/^\"|\"$//g;
449 $address =~ s/^\s+|\s+$//g; 530 $address = trim($address);
450 $address =~ s/^\<|\>$//g; 531 $address =~ s/^\<|\>$//g;
451 532
452 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars 533 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
@@ -462,9 +543,9 @@ sub format_email {
462 543
463 my $formatted_email; 544 my $formatted_email;
464 545
465 $name =~ s/^\s+|\s+$//g; 546 $name = trim($name);
466 $name =~ s/^\"|\"$//g; 547 $name =~ s/^\"|\"$//g;
467 $address =~ s/^\s+|\s+$//g; 548 $address = trim($address);
468 549
469 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars 550 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
470 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes 551 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
@@ -1286,19 +1367,25 @@ sub ERROR {
1286 if (report("ERROR", $_[0], $_[1])) { 1367 if (report("ERROR", $_[0], $_[1])) {
1287 our $clean = 0; 1368 our $clean = 0;
1288 our $cnt_error++; 1369 our $cnt_error++;
1370 return 1;
1289 } 1371 }
1372 return 0;
1290} 1373}
1291sub WARN { 1374sub WARN {
1292 if (report("WARNING", $_[0], $_[1])) { 1375 if (report("WARNING", $_[0], $_[1])) {
1293 our $clean = 0; 1376 our $clean = 0;
1294 our $cnt_warn++; 1377 our $cnt_warn++;
1378 return 1;
1295 } 1379 }
1380 return 0;
1296} 1381}
1297sub CHK { 1382sub CHK {
1298 if ($check && report("CHECK", $_[0], $_[1])) { 1383 if ($check && report("CHECK", $_[0], $_[1])) {
1299 our $clean = 0; 1384 our $clean = 0;
1300 our $cnt_chk++; 1385 our $cnt_chk++;
1386 return 1;
1301 } 1387 }
1388 return 0;
1302} 1389}
1303 1390
1304sub check_absolute_file { 1391sub check_absolute_file {
@@ -1329,6 +1416,29 @@ sub check_absolute_file {
1329 } 1416 }
1330} 1417}
1331 1418
1419sub trim {
1420 my ($string) = @_;
1421
1422 $string =~ s/(^\s+|\s+$)//g;
1423
1424 return $string;
1425}
1426
1427sub tabify {
1428 my ($leading) = @_;
1429
1430 my $source_indent = 8;
1431 my $max_spaces_before_tab = $source_indent - 1;
1432 my $spaces_to_tab = " " x $source_indent;
1433
1434 #convert leading spaces to tabs
1435 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
1436 #Remove spaces before a tab
1437 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
1438
1439 return "$leading";
1440}
1441
1332sub pos_last_openparen { 1442sub pos_last_openparen {
1333 my ($line) = @_; 1443 my ($line) = @_;
1334 1444
@@ -1406,7 +1516,6 @@ sub process {
1406 my %suppress_export; 1516 my %suppress_export;
1407 my $suppress_statement = 0; 1517 my $suppress_statement = 0;
1408 1518
1409 my %camelcase = ();
1410 1519
1411 # Pre-scan the patch sanitizing the lines. 1520 # Pre-scan the patch sanitizing the lines.
1412 # Pre-scan the patch looking for any __setup documentation. 1521 # Pre-scan the patch looking for any __setup documentation.
@@ -1420,6 +1529,8 @@ sub process {
1420 $linenr++; 1529 $linenr++;
1421 $line = $rawline; 1530 $line = $rawline;
1422 1531
1532 push(@fixed, $rawline) if ($fix);
1533
1423 if ($rawline=~/^\+\+\+\s+(\S+)/) { 1534 if ($rawline=~/^\+\+\+\s+(\S+)/) {
1424 $setup_docs = 0; 1535 $setup_docs = 0;
1425 if ($1 =~ m@Documentation/kernel-parameters.txt$@) { 1536 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
@@ -1611,16 +1722,29 @@ sub process {
1611 "Non-standard signature: $sign_off\n" . $herecurr); 1722 "Non-standard signature: $sign_off\n" . $herecurr);
1612 } 1723 }
1613 if (defined $space_before && $space_before ne "") { 1724 if (defined $space_before && $space_before ne "") {
1614 WARN("BAD_SIGN_OFF", 1725 if (WARN("BAD_SIGN_OFF",
1615 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr); 1726 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
1727 $fix) {
1728 $fixed[$linenr - 1] =
1729 "$ucfirst_sign_off $email";
1730 }
1616 } 1731 }
1617 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { 1732 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
1618 WARN("BAD_SIGN_OFF", 1733 if (WARN("BAD_SIGN_OFF",
1619 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr); 1734 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
1735 $fix) {
1736 $fixed[$linenr - 1] =
1737 "$ucfirst_sign_off $email";
1738 }
1739
1620 } 1740 }
1621 if (!defined $space_after || $space_after ne " ") { 1741 if (!defined $space_after || $space_after ne " ") {
1622 WARN("BAD_SIGN_OFF", 1742 if (WARN("BAD_SIGN_OFF",
1623 "Use a single space after $ucfirst_sign_off\n" . $herecurr); 1743 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
1744 $fix) {
1745 $fixed[$linenr - 1] =
1746 "$ucfirst_sign_off $email";
1747 }
1624 } 1748 }
1625 1749
1626 my ($email_name, $email_address, $comment) = parse_email($email); 1750 my ($email_name, $email_address, $comment) = parse_email($email);
@@ -1710,8 +1834,12 @@ sub process {
1710 1834
1711 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { 1835 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1712 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1836 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1713 ERROR("TRAILING_WHITESPACE", 1837 if (ERROR("TRAILING_WHITESPACE",
1714 "trailing whitespace\n" . $herevet); 1838 "trailing whitespace\n" . $herevet) &&
1839 $fix) {
1840 $fixed[$linenr - 1] =~ s/^(\+.*?)\s+$/$1/;
1841 }
1842
1715 $rpt_cleaners = 1; 1843 $rpt_cleaners = 1;
1716 } 1844 }
1717 1845
@@ -1806,8 +1934,12 @@ sub process {
1806 1934
1807# check for spaces before a quoted newline 1935# check for spaces before a quoted newline
1808 if ($rawline =~ /^.*\".*\s\\n/) { 1936 if ($rawline =~ /^.*\".*\s\\n/) {
1809 WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", 1937 if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
1810 "unnecessary whitespace before a quoted newline\n" . $herecurr); 1938 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
1939 $fix) {
1940 $fixed[$linenr - 1] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
1941 }
1942
1811 } 1943 }
1812 1944
1813# check for adding lines without a newline. 1945# check for adding lines without a newline.
@@ -1838,16 +1970,23 @@ sub process {
1838 if ($rawline =~ /^\+\s* \t\s*\S/ || 1970 if ($rawline =~ /^\+\s* \t\s*\S/ ||
1839 $rawline =~ /^\+\s* \s*/) { 1971 $rawline =~ /^\+\s* \s*/) {
1840 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1972 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1841 ERROR("CODE_INDENT",
1842 "code indent should use tabs where possible\n" . $herevet);
1843 $rpt_cleaners = 1; 1973 $rpt_cleaners = 1;
1974 if (ERROR("CODE_INDENT",
1975 "code indent should use tabs where possible\n" . $herevet) &&
1976 $fix) {
1977 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
1978 }
1844 } 1979 }
1845 1980
1846# check for space before tabs. 1981# check for space before tabs.
1847 if ($rawline =~ /^\+/ && $rawline =~ / \t/) { 1982 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
1848 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1983 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1849 WARN("SPACE_BEFORE_TAB", 1984 if (WARN("SPACE_BEFORE_TAB",
1850 "please, no space before tabs\n" . $herevet); 1985 "please, no space before tabs\n" . $herevet) &&
1986 $fix) {
1987 $fixed[$linenr - 1] =~
1988 s/(^\+.*) +\t/$1\t/;
1989 }
1851 } 1990 }
1852 1991
1853# check for && or || at the start of a line 1992# check for && or || at the start of a line
@@ -1875,25 +2014,42 @@ sub process {
1875 2014
1876 if ($newindent ne $goodtabindent && 2015 if ($newindent ne $goodtabindent &&
1877 $newindent ne $goodspaceindent) { 2016 $newindent ne $goodspaceindent) {
1878 CHK("PARENTHESIS_ALIGNMENT", 2017
1879 "Alignment should match open parenthesis\n" . $hereprev); 2018 if (CHK("PARENTHESIS_ALIGNMENT",
2019 "Alignment should match open parenthesis\n" . $hereprev) &&
2020 $fix && $line =~ /^\+/) {
2021 $fixed[$linenr - 1] =~
2022 s/^\+[ \t]*/\+$goodtabindent/;
2023 }
1880 } 2024 }
1881 } 2025 }
1882 } 2026 }
1883 2027
1884 if ($line =~ /^\+.*\*[ \t]*\)[ \t]+/) { 2028 if ($line =~ /^\+.*\*[ \t]*\)[ \t]+(?!$Assignment|$Arithmetic)/) {
1885 CHK("SPACING", 2029 if (CHK("SPACING",
1886 "No space is necessary after a cast\n" . $hereprev); 2030 "No space is necessary after a cast\n" . $hereprev) &&
2031 $fix) {
2032 $fixed[$linenr - 1] =~
2033 s/^(\+.*\*[ \t]*\))[ \t]+/$1/;
2034 }
1887 } 2035 }
1888 2036
1889 if ($realfile =~ m@^(drivers/net/|net/)@ && 2037 if ($realfile =~ m@^(drivers/net/|net/)@ &&
1890 $rawline =~ /^\+[ \t]*\/\*[ \t]*$/ && 2038 $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
1891 $prevrawline =~ /^\+[ \t]*$/) { 2039 $rawline =~ /^\+[ \t]*\*/) {
1892 WARN("NETWORKING_BLOCK_COMMENT_STYLE", 2040 WARN("NETWORKING_BLOCK_COMMENT_STYLE",
1893 "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev); 2041 "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
1894 } 2042 }
1895 2043
1896 if ($realfile =~ m@^(drivers/net/|net/)@ && 2044 if ($realfile =~ m@^(drivers/net/|net/)@ &&
2045 $prevrawline =~ /^\+[ \t]*\/\*/ && #starting /*
2046 $prevrawline !~ /\*\/[ \t]*$/ && #no trailing */
2047 $rawline !~ /^\+[ \t]*\*/) { #no leading *
2048 WARN("NETWORKING_BLOCK_COMMENT_STYLE",
2049 "networking block comments start with * on subsequent lines\n" . $hereprev);
2050 }
2051
2052 if ($realfile =~ m@^(drivers/net/|net/)@ &&
1897 $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */ 2053 $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */
1898 $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/ 2054 $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
1899 $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/ 2055 $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/
@@ -1907,10 +2063,13 @@ sub process {
1907# 1) within comments 2063# 1) within comments
1908# 2) indented preprocessor commands 2064# 2) indented preprocessor commands
1909# 3) hanging labels 2065# 3) hanging labels
1910 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) { 2066 if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/) {
1911 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 2067 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1912 WARN("LEADING_SPACE", 2068 if (WARN("LEADING_SPACE",
1913 "please, no spaces at the start of a line\n" . $herevet); 2069 "please, no spaces at the start of a line\n" . $herevet) &&
2070 $fix) {
2071 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
2072 }
1914 } 2073 }
1915 2074
1916# check we are in a valid C source file if not then ignore this hunk 2075# check we are in a valid C source file if not then ignore this hunk
@@ -2200,7 +2359,7 @@ sub process {
2200 $prev_values = substr($curr_values, -1); 2359 $prev_values = substr($curr_values, -1);
2201 2360
2202#ignore lines not being added 2361#ignore lines not being added
2203 if ($line=~/^[^\+]/) {next;} 2362 next if ($line =~ /^[^\+]/);
2204 2363
2205# TEST: allow direct testing of the type matcher. 2364# TEST: allow direct testing of the type matcher.
2206 if ($dbg_type) { 2365 if ($dbg_type) {
@@ -2251,8 +2410,15 @@ sub process {
2251 2410
2252# no C99 // comments 2411# no C99 // comments
2253 if ($line =~ m{//}) { 2412 if ($line =~ m{//}) {
2254 ERROR("C99_COMMENTS", 2413 if (ERROR("C99_COMMENTS",
2255 "do not use C99 // comments\n" . $herecurr); 2414 "do not use C99 // comments\n" . $herecurr) &&
2415 $fix) {
2416 my $line = $fixed[$linenr - 1];
2417 if ($line =~ /\/\/(.*)$/) {
2418 my $comment = trim($1);
2419 $fixed[$linenr - 1] =~ s@\/\/(.*)$@/\* $comment \*/@;
2420 }
2421 }
2256 } 2422 }
2257 # Remove C99 comments. 2423 # Remove C99 comments.
2258 $line =~ s@//.*@@; 2424 $line =~ s@//.*@@;
@@ -2351,7 +2517,7 @@ sub process {
2351 # (char*[ const]) 2517 # (char*[ const])
2352 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) { 2518 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
2353 #print "AA<$1>\n"; 2519 #print "AA<$1>\n";
2354 my ($from, $to) = ($2, $2); 2520 my ($ident, $from, $to) = ($1, $2, $2);
2355 2521
2356 # Should start with a space. 2522 # Should start with a space.
2357 $to =~ s/^(\S)/ $1/; 2523 $to =~ s/^(\S)/ $1/;
@@ -2361,15 +2527,22 @@ sub process {
2361 while ($to =~ s/\*\s+\*/\*\*/) { 2527 while ($to =~ s/\*\s+\*/\*\*/) {
2362 } 2528 }
2363 2529
2364 #print "from<$from> to<$to>\n"; 2530## print "1: from<$from> to<$to> ident<$ident>\n";
2365 if ($from ne $to) { 2531 if ($from ne $to) {
2366 ERROR("POINTER_LOCATION", 2532 if (ERROR("POINTER_LOCATION",
2367 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); 2533 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr) &&
2534 $fix) {
2535 my $sub_from = $ident;
2536 my $sub_to = $ident;
2537 $sub_to =~ s/\Q$from\E/$to/;
2538 $fixed[$linenr - 1] =~
2539 s@\Q$sub_from\E@$sub_to@;
2540 }
2368 } 2541 }
2369 } 2542 }
2370 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) { 2543 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
2371 #print "BB<$1>\n"; 2544 #print "BB<$1>\n";
2372 my ($from, $to, $ident) = ($2, $2, $3); 2545 my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
2373 2546
2374 # Should start with a space. 2547 # Should start with a space.
2375 $to =~ s/^(\S)/ $1/; 2548 $to =~ s/^(\S)/ $1/;
@@ -2381,10 +2554,18 @@ sub process {
2381 # Modifiers should have spaces. 2554 # Modifiers should have spaces.
2382 $to =~ s/(\b$Modifier$)/$1 /; 2555 $to =~ s/(\b$Modifier$)/$1 /;
2383 2556
2384 #print "from<$from> to<$to> ident<$ident>\n"; 2557## print "2: from<$from> to<$to> ident<$ident>\n";
2385 if ($from ne $to && $ident !~ /^$Modifier$/) { 2558 if ($from ne $to && $ident !~ /^$Modifier$/) {
2386 ERROR("POINTER_LOCATION", 2559 if (ERROR("POINTER_LOCATION",
2387 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); 2560 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr) &&
2561 $fix) {
2562
2563 my $sub_from = $match;
2564 my $sub_to = $match;
2565 $sub_to =~ s/\Q$from\E/$to/;
2566 $fixed[$linenr - 1] =~
2567 s@\Q$sub_from\E@$sub_to@;
2568 }
2388 } 2569 }
2389 } 2570 }
2390 2571
@@ -2470,9 +2651,13 @@ sub process {
2470 } 2651 }
2471 2652
2472# missing space after union, struct or enum definition 2653# missing space after union, struct or enum definition
2473 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) { 2654 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
2474 WARN("SPACING", 2655 if (WARN("SPACING",
2475 "missing space after $1 definition\n" . $herecurr); 2656 "missing space after $1 definition\n" . $herecurr) &&
2657 $fix) {
2658 $fixed[$linenr - 1] =~
2659 s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
2660 }
2476 } 2661 }
2477 2662
2478# check for spacing round square brackets; allowed: 2663# check for spacing round square brackets; allowed:
@@ -2484,8 +2669,12 @@ sub process {
2484 if ($prefix !~ /$Type\s+$/ && 2669 if ($prefix !~ /$Type\s+$/ &&
2485 ($where != 0 || $prefix !~ /^.\s+$/) && 2670 ($where != 0 || $prefix !~ /^.\s+$/) &&
2486 $prefix !~ /[{,]\s+$/) { 2671 $prefix !~ /[{,]\s+$/) {
2487 ERROR("BRACKET_SPACE", 2672 if (ERROR("BRACKET_SPACE",
2488 "space prohibited before open square bracket '['\n" . $herecurr); 2673 "space prohibited before open square bracket '['\n" . $herecurr) &&
2674 $fix) {
2675 $fixed[$linenr - 1] =~
2676 s/^(\+.*?)\s+\[/$1\[/;
2677 }
2489 } 2678 }
2490 } 2679 }
2491 2680
@@ -2502,7 +2691,6 @@ sub process {
2502 __attribute__|format|__extension__| 2691 __attribute__|format|__extension__|
2503 asm|__asm__)$/x) 2692 asm|__asm__)$/x)
2504 { 2693 {
2505
2506 # cpp #define statements have non-optional spaces, ie 2694 # cpp #define statements have non-optional spaces, ie
2507 # if there is a space between the name and the open 2695 # if there is a space between the name and the open
2508 # parenthesis it is simply not a parameter group. 2696 # parenthesis it is simply not a parameter group.
@@ -2516,19 +2704,20 @@ sub process {
2516 } elsif ($ctx =~ /$Type$/) { 2704 } elsif ($ctx =~ /$Type$/) {
2517 2705
2518 } else { 2706 } else {
2519 WARN("SPACING", 2707 if (WARN("SPACING",
2520 "space prohibited between function name and open parenthesis '('\n" . $herecurr); 2708 "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
2709 $fix) {
2710 $fixed[$linenr - 1] =~
2711 s/\b$name\s+\(/$name\(/;
2712 }
2521 } 2713 }
2522 } 2714 }
2523 2715
2524# check for whitespace before a non-naked semicolon
2525 if ($line =~ /^\+.*\S\s+;/) {
2526 WARN("SPACING",
2527 "space prohibited before semicolon\n" . $herecurr);
2528 }
2529
2530# Check operator spacing. 2716# Check operator spacing.
2531 if (!($line=~/\#\s*include/)) { 2717 if (!($line=~/\#\s*include/)) {
2718 my $fixed_line = "";
2719 my $line_fixed = 0;
2720
2532 my $ops = qr{ 2721 my $ops = qr{
2533 <<=|>>=|<=|>=|==|!=| 2722 <<=|>>=|<=|>=|==|!=|
2534 \+=|-=|\*=|\/=|%=|\^=|\|=|&=| 2723 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
@@ -2537,11 +2726,30 @@ sub process {
2537 \?|: 2726 \?|:
2538 }x; 2727 }x;
2539 my @elements = split(/($ops|;)/, $opline); 2728 my @elements = split(/($ops|;)/, $opline);
2729
2730## print("element count: <" . $#elements . ">\n");
2731## foreach my $el (@elements) {
2732## print("el: <$el>\n");
2733## }
2734
2735 my @fix_elements = ();
2540 my $off = 0; 2736 my $off = 0;
2541 2737
2738 foreach my $el (@elements) {
2739 push(@fix_elements, substr($rawline, $off, length($el)));
2740 $off += length($el);
2741 }
2742
2743 $off = 0;
2744
2542 my $blank = copy_spacing($opline); 2745 my $blank = copy_spacing($opline);
2543 2746
2544 for (my $n = 0; $n < $#elements; $n += 2) { 2747 for (my $n = 0; $n < $#elements; $n += 2) {
2748
2749 my $good = $fix_elements[$n] . $fix_elements[$n + 1];
2750
2751## print("n: <$n> good: <$good>\n");
2752
2545 $off += length($elements[$n]); 2753 $off += length($elements[$n]);
2546 2754
2547 # Pick up the preceding and succeeding characters. 2755 # Pick up the preceding and succeeding characters.
@@ -2598,8 +2806,11 @@ sub process {
2598 } elsif ($op eq ';') { 2806 } elsif ($op eq ';') {
2599 if ($ctx !~ /.x[WEBC]/ && 2807 if ($ctx !~ /.x[WEBC]/ &&
2600 $cc !~ /^\\/ && $cc !~ /^;/) { 2808 $cc !~ /^\\/ && $cc !~ /^;/) {
2601 ERROR("SPACING", 2809 if (ERROR("SPACING",
2602 "space required after that '$op' $at\n" . $hereptr); 2810 "space required after that '$op' $at\n" . $hereptr)) {
2811 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
2812 $line_fixed = 1;
2813 }
2603 } 2814 }
2604 2815
2605 # // is a comment 2816 # // is a comment
@@ -2610,15 +2821,24 @@ sub process {
2610 # : when part of a bitfield 2821 # : when part of a bitfield
2611 } elsif ($op eq '->' || $opv eq ':B') { 2822 } elsif ($op eq '->' || $opv eq ':B') {
2612 if ($ctx =~ /Wx.|.xW/) { 2823 if ($ctx =~ /Wx.|.xW/) {
2613 ERROR("SPACING", 2824 if (ERROR("SPACING",
2614 "spaces prohibited around that '$op' $at\n" . $hereptr); 2825 "spaces prohibited around that '$op' $at\n" . $hereptr)) {
2826 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2827 $line_fixed = 1;
2828 if (defined $fix_elements[$n + 2]) {
2829 $fix_elements[$n + 2] =~ s/^\s+//;
2830 }
2831 }
2615 } 2832 }
2616 2833
2617 # , must have a space on the right. 2834 # , must have a space on the right.
2618 } elsif ($op eq ',') { 2835 } elsif ($op eq ',') {
2619 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { 2836 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
2620 ERROR("SPACING", 2837 if (ERROR("SPACING",
2621 "space required after that '$op' $at\n" . $hereptr); 2838 "space required after that '$op' $at\n" . $hereptr)) {
2839 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]) . " ";
2840 $line_fixed = 1;
2841 }
2622 } 2842 }
2623 2843
2624 # '*' as part of a type definition -- reported already. 2844 # '*' as part of a type definition -- reported already.
@@ -2632,34 +2852,58 @@ sub process {
2632 $opv eq '*U' || $opv eq '-U' || 2852 $opv eq '*U' || $opv eq '-U' ||
2633 $opv eq '&U' || $opv eq '&&U') { 2853 $opv eq '&U' || $opv eq '&&U') {
2634 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { 2854 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
2635 ERROR("SPACING", 2855 if (ERROR("SPACING",
2636 "space required before that '$op' $at\n" . $hereptr); 2856 "space required before that '$op' $at\n" . $hereptr)) {
2857 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
2858 $line_fixed = 1;
2859 }
2637 } 2860 }
2638 if ($op eq '*' && $cc =~/\s*$Modifier\b/) { 2861 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
2639 # A unary '*' may be const 2862 # A unary '*' may be const
2640 2863
2641 } elsif ($ctx =~ /.xW/) { 2864 } elsif ($ctx =~ /.xW/) {
2642 ERROR("SPACING", 2865 if (ERROR("SPACING",
2643 "space prohibited after that '$op' $at\n" . $hereptr); 2866 "space prohibited after that '$op' $at\n" . $hereptr)) {
2867 $fixed_line =~ s/\s+$//;
2868 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2869 $line_fixed = 1;
2870 if (defined $fix_elements[$n + 2]) {
2871 $fix_elements[$n + 2] =~ s/^\s+//;
2872 }
2873 }
2644 } 2874 }
2645 2875
2646 # unary ++ and unary -- are allowed no space on one side. 2876 # unary ++ and unary -- are allowed no space on one side.
2647 } elsif ($op eq '++' or $op eq '--') { 2877 } elsif ($op eq '++' or $op eq '--') {
2648 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { 2878 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
2649 ERROR("SPACING", 2879 if (ERROR("SPACING",
2650 "space required one side of that '$op' $at\n" . $hereptr); 2880 "space required one side of that '$op' $at\n" . $hereptr)) {
2881 $fixed_line =~ s/\s+$//;
2882 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]) . " ";
2883 $line_fixed = 1;
2884 }
2651 } 2885 }
2652 if ($ctx =~ /Wx[BE]/ || 2886 if ($ctx =~ /Wx[BE]/ ||
2653 ($ctx =~ /Wx./ && $cc =~ /^;/)) { 2887 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
2654 ERROR("SPACING", 2888 if (ERROR("SPACING",
2655 "space prohibited before that '$op' $at\n" . $hereptr); 2889 "space prohibited before that '$op' $at\n" . $hereptr)) {
2890 $fixed_line =~ s/\s+$//;
2891 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2892 $line_fixed = 1;
2893 }
2656 } 2894 }
2657 if ($ctx =~ /ExW/) { 2895 if ($ctx =~ /ExW/) {
2658 ERROR("SPACING", 2896 if (ERROR("SPACING",
2659 "space prohibited after that '$op' $at\n" . $hereptr); 2897 "space prohibited after that '$op' $at\n" . $hereptr)) {
2898 $fixed_line =~ s/\s+$//;
2899 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2900 $line_fixed = 1;
2901 if (defined $fix_elements[$n + 2]) {
2902 $fix_elements[$n + 2] =~ s/^\s+//;
2903 }
2904 }
2660 } 2905 }
2661 2906
2662
2663 # << and >> may either have or not have spaces both sides 2907 # << and >> may either have or not have spaces both sides
2664 } elsif ($op eq '<<' or $op eq '>>' or 2908 } elsif ($op eq '<<' or $op eq '>>' or
2665 $op eq '&' or $op eq '^' or $op eq '|' or 2909 $op eq '&' or $op eq '^' or $op eq '|' or
@@ -2668,17 +2912,23 @@ sub process {
2668 $op eq '%') 2912 $op eq '%')
2669 { 2913 {
2670 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { 2914 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
2671 ERROR("SPACING", 2915 if (ERROR("SPACING",
2672 "need consistent spacing around '$op' $at\n" . 2916 "need consistent spacing around '$op' $at\n" . $hereptr)) {
2673 $hereptr); 2917 $fixed_line =~ s/\s+$//;
2918 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
2919 $line_fixed = 1;
2920 }
2674 } 2921 }
2675 2922
2676 # A colon needs no spaces before when it is 2923 # A colon needs no spaces before when it is
2677 # terminating a case value or a label. 2924 # terminating a case value or a label.
2678 } elsif ($opv eq ':C' || $opv eq ':L') { 2925 } elsif ($opv eq ':C' || $opv eq ':L') {
2679 if ($ctx =~ /Wx./) { 2926 if ($ctx =~ /Wx./) {
2680 ERROR("SPACING", 2927 if (ERROR("SPACING",
2681 "space prohibited before that '$op' $at\n" . $hereptr); 2928 "space prohibited before that '$op' $at\n" . $hereptr)) {
2929 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2930 $line_fixed = 1;
2931 }
2682 } 2932 }
2683 2933
2684 # All the others need spaces both sides. 2934 # All the others need spaces both sides.
@@ -2701,11 +2951,39 @@ sub process {
2701 } 2951 }
2702 2952
2703 if ($ok == 0) { 2953 if ($ok == 0) {
2704 ERROR("SPACING", 2954 if (ERROR("SPACING",
2705 "spaces required around that '$op' $at\n" . $hereptr); 2955 "spaces required around that '$op' $at\n" . $hereptr)) {
2956 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
2957 $good = $fix_elements[$n] . " " . trim($fix_elements[$n + 1]) . " ";
2958 $line_fixed = 1;
2959 }
2706 } 2960 }
2707 } 2961 }
2708 $off += length($elements[$n + 1]); 2962 $off += length($elements[$n + 1]);
2963
2964## print("n: <$n> GOOD: <$good>\n");
2965
2966 $fixed_line = $fixed_line . $good;
2967 }
2968
2969 if (($#elements % 2) == 0) {
2970 $fixed_line = $fixed_line . $fix_elements[$#elements];
2971 }
2972
2973 if ($fix && $line_fixed && $fixed_line ne $fixed[$linenr - 1]) {
2974 $fixed[$linenr - 1] = $fixed_line;
2975 }
2976
2977
2978 }
2979
2980# check for whitespace before a non-naked semicolon
2981 if ($line =~ /^\+.*\S\s+;/) {
2982 if (WARN("SPACING",
2983 "space prohibited before semicolon\n" . $herecurr) &&
2984 $fix) {
2985 1 while $fixed[$linenr - 1] =~
2986 s/^(\+.*\S)\s+;/$1;/;
2709 } 2987 }
2710 } 2988 }
2711 2989
@@ -2734,10 +3012,22 @@ sub process {
2734#need space before brace following if, while, etc 3012#need space before brace following if, while, etc
2735 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || 3013 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
2736 $line =~ /do{/) { 3014 $line =~ /do{/) {
2737 ERROR("SPACING", 3015 if (ERROR("SPACING",
2738 "space required before the open brace '{'\n" . $herecurr); 3016 "space required before the open brace '{'\n" . $herecurr) &&
3017 $fix) {
3018 $fixed[$linenr - 1] =~
3019 s/^(\+.*(?:do|\))){/$1 {/;
3020 }
2739 } 3021 }
2740 3022
3023## # check for blank lines before declarations
3024## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
3025## $prevrawline =~ /^.\s*$/) {
3026## WARN("SPACING",
3027## "No blank lines before declarations\n" . $hereprev);
3028## }
3029##
3030
2741# closing brace should have a space following it when it has anything 3031# closing brace should have a space following it when it has anything
2742# on the line 3032# on the line
2743 if ($line =~ /}(?!(?:,|;|\)))\S/) { 3033 if ($line =~ /}(?!(?:,|;|\)))\S/) {
@@ -2747,32 +3037,52 @@ sub process {
2747 3037
2748# check spacing on square brackets 3038# check spacing on square brackets
2749 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { 3039 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
2750 ERROR("SPACING", 3040 if (ERROR("SPACING",
2751 "space prohibited after that open square bracket '['\n" . $herecurr); 3041 "space prohibited after that open square bracket '['\n" . $herecurr) &&
3042 $fix) {
3043 $fixed[$linenr - 1] =~
3044 s/\[\s+/\[/;
3045 }
2752 } 3046 }
2753 if ($line =~ /\s\]/) { 3047 if ($line =~ /\s\]/) {
2754 ERROR("SPACING", 3048 if (ERROR("SPACING",
2755 "space prohibited before that close square bracket ']'\n" . $herecurr); 3049 "space prohibited before that close square bracket ']'\n" . $herecurr) &&
3050 $fix) {
3051 $fixed[$linenr - 1] =~
3052 s/\s+\]/\]/;
3053 }
2756 } 3054 }
2757 3055
2758# check spacing on parentheses 3056# check spacing on parentheses
2759 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && 3057 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
2760 $line !~ /for\s*\(\s+;/) { 3058 $line !~ /for\s*\(\s+;/) {
2761 ERROR("SPACING", 3059 if (ERROR("SPACING",
2762 "space prohibited after that open parenthesis '('\n" . $herecurr); 3060 "space prohibited after that open parenthesis '('\n" . $herecurr) &&
3061 $fix) {
3062 $fixed[$linenr - 1] =~
3063 s/\(\s+/\(/;
3064 }
2763 } 3065 }
2764 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && 3066 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
2765 $line !~ /for\s*\(.*;\s+\)/ && 3067 $line !~ /for\s*\(.*;\s+\)/ &&
2766 $line !~ /:\s+\)/) { 3068 $line !~ /:\s+\)/) {
2767 ERROR("SPACING", 3069 if (ERROR("SPACING",
2768 "space prohibited before that close parenthesis ')'\n" . $herecurr); 3070 "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
3071 $fix) {
3072 $fixed[$linenr - 1] =~
3073 s/\s+\)/\)/;
3074 }
2769 } 3075 }
2770 3076
2771#goto labels aren't indented, allow a single space however 3077#goto labels aren't indented, allow a single space however
2772 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and 3078 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
2773 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { 3079 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
2774 WARN("INDENTED_LABEL", 3080 if (WARN("INDENTED_LABEL",
2775 "labels should not be indented\n" . $herecurr); 3081 "labels should not be indented\n" . $herecurr) &&
3082 $fix) {
3083 $fixed[$linenr - 1] =~
3084 s/^(.)\s+/$1/;
3085 }
2776 } 3086 }
2777 3087
2778# Return is not a function. 3088# Return is not a function.
@@ -2809,8 +3119,13 @@ sub process {
2809 } 3119 }
2810 3120
2811# Need a space before open parenthesis after if, while etc 3121# Need a space before open parenthesis after if, while etc
2812 if ($line=~/\b(if|while|for|switch)\(/) { 3122 if ($line =~ /\b(if|while|for|switch)\(/) {
2813 ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr); 3123 if (ERROR("SPACING",
3124 "space required before the open parenthesis '('\n" . $herecurr) &&
3125 $fix) {
3126 $fixed[$linenr - 1] =~
3127 s/\b(if|while|for|switch)\(/$1 \(/;
3128 }
2814 } 3129 }
2815 3130
2816# Check for illegal assignment in if conditional -- and check for trailing 3131# Check for illegal assignment in if conditional -- and check for trailing
@@ -2934,16 +3249,29 @@ sub process {
2934 } 3249 }
2935 } 3250 }
2936 3251
2937#CamelCase 3252#Specific variable tests
2938 while ($line =~ m{($Constant|$Lval)}g) { 3253 while ($line =~ m{($Constant|$Lval)}g) {
2939 my $var = $1; 3254 my $var = $1;
2940 if ($var !~ /$Constant/ && 3255
2941 $var =~ /[A-Z]\w*[a-z]|[a-z]\w*[A-Z]/ && 3256#gcc binary extension
2942 $var !~ /"^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && 3257 if ($var =~ /^$Binary$/) {
2943 !defined $camelcase{$var}) { 3258 WARN("GCC_BINARY_CONSTANT",
2944 $camelcase{$var} = 1; 3259 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr);
2945 WARN("CAMELCASE", 3260 }
2946 "Avoid CamelCase: <$var>\n" . $herecurr); 3261
3262#CamelCase
3263 if ($var !~ /^$Constant$/ &&
3264 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
3265#Ignore Page<foo> variants
3266 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
3267#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
3268 $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) {
3269 seed_camelcase_includes() if ($check);
3270 if (!defined $camelcase{$var}) {
3271 $camelcase{$var} = 1;
3272 CHK("CAMELCASE",
3273 "Avoid CamelCase: <$var>\n" . $herecurr);
3274 }
2947 } 3275 }
2948 } 3276 }
2949 3277
@@ -3021,7 +3349,7 @@ sub process {
3021 if ($dstat ne '' && 3349 if ($dstat ne '' &&
3022 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), 3350 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
3023 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo(); 3351 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
3024 $dstat !~ /^[!~-]?(?:$Ident|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo 3352 $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
3025 $dstat !~ /^'X'$/ && # character constants 3353 $dstat !~ /^'X'$/ && # character constants
3026 $dstat !~ /$exceptions/ && 3354 $dstat !~ /$exceptions/ &&
3027 $dstat !~ /^\.$Ident\s*=/ && # .foo = 3355 $dstat !~ /^\.$Ident\s*=/ && # .foo =
@@ -3230,11 +3558,11 @@ sub process {
3230 } 3558 }
3231 3559
3232# check for unnecessary blank lines around braces 3560# check for unnecessary blank lines around braces
3233 if (($line =~ /^.\s*}\s*$/ && $prevline =~ /^.\s*$/)) { 3561 if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
3234 CHK("BRACES", 3562 CHK("BRACES",
3235 "Blank lines aren't necessary before a close brace '}'\n" . $hereprev); 3563 "Blank lines aren't necessary before a close brace '}'\n" . $hereprev);
3236 } 3564 }
3237 if (($line =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) { 3565 if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
3238 CHK("BRACES", 3566 CHK("BRACES",
3239 "Blank lines aren't necessary after an open brace '{'\n" . $hereprev); 3567 "Blank lines aren't necessary after an open brace '{'\n" . $hereprev);
3240 } 3568 }
@@ -3279,6 +3607,18 @@ sub process {
3279 } 3607 }
3280 } 3608 }
3281 3609
3610# check for comparisons of jiffies
3611 if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
3612 WARN("JIFFIES_COMPARISON",
3613 "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
3614 }
3615
3616# check for comparisons of get_jiffies_64()
3617 if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
3618 WARN("JIFFIES_COMPARISON",
3619 "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
3620 }
3621
3282# warn about #ifdefs in C files 3622# warn about #ifdefs in C files
3283# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { 3623# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
3284# print "#ifdef in C files should be avoided\n"; 3624# print "#ifdef in C files should be avoided\n";
@@ -3288,8 +3628,13 @@ sub process {
3288 3628
3289# warn about spacing in #ifdefs 3629# warn about spacing in #ifdefs
3290 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { 3630 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
3291 ERROR("SPACING", 3631 if (ERROR("SPACING",
3292 "exactly one space required after that #$1\n" . $herecurr); 3632 "exactly one space required after that #$1\n" . $herecurr) &&
3633 $fix) {
3634 $fixed[$linenr - 1] =~
3635 s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
3636 }
3637
3293 } 3638 }
3294 3639
3295# check for spinlock_t definitions without a comment. 3640# check for spinlock_t definitions without a comment.
@@ -3495,6 +3840,14 @@ sub process {
3495 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); 3840 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
3496 } 3841 }
3497 3842
3843# alloc style
3844# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
3845 if ($^V && $^V ge 5.10.0 &&
3846 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
3847 CHK("ALLOC_SIZEOF_STRUCT",
3848 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
3849 }
3850
3498# check for krealloc arg reuse 3851# check for krealloc arg reuse
3499 if ($^V && $^V ge 5.10.0 && 3852 if ($^V && $^V ge 5.10.0 &&
3500 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { 3853 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) {
@@ -3540,6 +3893,33 @@ sub process {
3540 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr); 3893 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
3541 } 3894 }
3542 3895
3896# check for comparisons against true and false
3897 if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
3898 my $lead = $1;
3899 my $arg = $2;
3900 my $test = $3;
3901 my $otype = $4;
3902 my $trail = $5;
3903 my $op = "!";
3904
3905 ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
3906
3907 my $type = lc($otype);
3908 if ($type =~ /^(?:true|false)$/) {
3909 if (("$test" eq "==" && "$type" eq "true") ||
3910 ("$test" eq "!=" && "$type" eq "false")) {
3911 $op = "";
3912 }
3913
3914 CHK("BOOL_COMPARISON",
3915 "Using comparison to $otype is error prone\n" . $herecurr);
3916
3917## maybe suggesting a correct construct would better
3918## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
3919
3920 }
3921 }
3922
3543# check for semaphores initialized locked 3923# check for semaphores initialized locked
3544 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { 3924 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
3545 WARN("CONSIDER_COMPLETION", 3925 WARN("CONSIDER_COMPLETION",
@@ -3717,6 +4097,40 @@ sub process {
3717 print "\n\n"; 4097 print "\n\n";
3718 } 4098 }
3719 4099
4100 if ($clean == 0 && $fix && "@rawlines" ne "@fixed") {
4101 my $newfile = $filename . ".EXPERIMENTAL-checkpatch-fixes";
4102 my $linecount = 0;
4103 my $f;
4104
4105 open($f, '>', $newfile)
4106 or die "$P: Can't open $newfile for write\n";
4107 foreach my $fixed_line (@fixed) {
4108 $linecount++;
4109 if ($file) {
4110 if ($linecount > 3) {
4111 $fixed_line =~ s/^\+//;
4112 print $f $fixed_line. "\n";
4113 }
4114 } else {
4115 print $f $fixed_line . "\n";
4116 }
4117 }
4118 close($f);
4119
4120 if (!$quiet) {
4121 print << "EOM";
4122Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
4123
4124Do _NOT_ trust the results written to this file.
4125Do _NOT_ submit these changes without inspecting them for correctness.
4126
4127This EXPERIMENTAL file is simply a convenience to help rewrite patches.
4128No warranties, expressed or implied...
4129
4130EOM
4131 }
4132 }
4133
3720 if ($clean == 1 && $quiet == 0) { 4134 if ($clean == 1 && $quiet == 0) {
3721 print "$vname has no obvious style problems and is ready for submission.\n" 4135 print "$vname has no obvious style problems and is ready for submission.\n"
3722 } 4136 }
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index e66d4d258e1a..bb5d115ca671 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -177,5 +177,11 @@ int main(void)
177 DEVID(mei_cl_device_id); 177 DEVID(mei_cl_device_id);
178 DEVID_FIELD(mei_cl_device_id, name); 178 DEVID_FIELD(mei_cl_device_id, name);
179 179
180 DEVID(rio_device_id);
181 DEVID_FIELD(rio_device_id, did);
182 DEVID_FIELD(rio_device_id, vid);
183 DEVID_FIELD(rio_device_id, asm_did);
184 DEVID_FIELD(rio_device_id, asm_vid);
185
180 return 0; 186 return 0;
181} 187}
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 45f9a3377dcd..d9e67b719f08 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1145,6 +1145,26 @@ static int do_mei_entry(const char *filename, void *symval,
1145} 1145}
1146ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry); 1146ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry);
1147 1147
1148/* Looks like: rapidio:vNdNavNadN */
1149static int do_rio_entry(const char *filename,
1150 void *symval, char *alias)
1151{
1152 DEF_FIELD(symval, rio_device_id, did);
1153 DEF_FIELD(symval, rio_device_id, vid);
1154 DEF_FIELD(symval, rio_device_id, asm_did);
1155 DEF_FIELD(symval, rio_device_id, asm_vid);
1156
1157 strcpy(alias, "rapidio:");
1158 ADD(alias, "v", vid != RIO_ANY_ID, vid);
1159 ADD(alias, "d", did != RIO_ANY_ID, did);
1160 ADD(alias, "av", asm_vid != RIO_ANY_ID, asm_vid);
1161 ADD(alias, "ad", asm_did != RIO_ANY_ID, asm_did);
1162
1163 add_wildcard(alias);
1164 return 1;
1165}
1166ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
1167
1148/* Does namelen bytes of name exactly match the symbol? */ 1168/* Does namelen bytes of name exactly match the symbol? */
1149static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1169static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1150{ 1170{