Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit) |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 4 | # (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc) |
| 5 | # Licensed under the terms of the GNU GPL License version 2 |
| 6 | |
| 7 | use strict; |
| 8 | |
| 9 | my $P = $0; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 10 | $P =~ s@.*/@@g; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 11 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 12 | my $V = '0.10'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 13 | |
| 14 | use Getopt::Long qw(:config no_auto_abbrev); |
| 15 | |
| 16 | my $quiet = 0; |
| 17 | my $tree = 1; |
| 18 | my $chk_signoff = 1; |
| 19 | my $chk_patch = 1; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 20 | my $tst_type = 0; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 21 | GetOptions( |
| 22 | 'q|quiet' => \$quiet, |
| 23 | 'tree!' => \$tree, |
| 24 | 'signoff!' => \$chk_signoff, |
| 25 | 'patch!' => \$chk_patch, |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 26 | 'test-type!' => \$tst_type, |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 27 | ) or exit; |
| 28 | |
| 29 | my $exit = 0; |
| 30 | |
| 31 | if ($#ARGV < 0) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 32 | print "usage: $P [options] patchfile\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 33 | print "version: $V\n"; |
| 34 | print "options: -q => quiet\n"; |
| 35 | print " --no-tree => run without a kernel tree\n"; |
| 36 | exit(1); |
| 37 | } |
| 38 | |
| 39 | if ($tree && !top_of_kernel_tree()) { |
| 40 | print "Must be run from the top-level dir. of a kernel tree\n"; |
| 41 | exit(2); |
| 42 | } |
| 43 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 44 | my @dep_includes = (); |
| 45 | my @dep_functions = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 46 | my $removal = 'Documentation/feature-removal-schedule.txt'; |
| 47 | if ($tree && -f $removal) { |
| 48 | open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n"; |
| 49 | while (<REMOVE>) { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 50 | if (/^Check:\s+(.*\S)/) { |
| 51 | for my $entry (split(/[, ]+/, $1)) { |
| 52 | if ($entry =~ m@include/(.*)@) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 53 | push(@dep_includes, $1); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 54 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 55 | } elsif ($entry !~ m@/@) { |
| 56 | push(@dep_functions, $entry); |
| 57 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 58 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 63 | my @rawlines = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 64 | while (<>) { |
| 65 | chomp; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 66 | push(@rawlines, $_); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 67 | if (eof(ARGV)) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 68 | if (!process($ARGV, @rawlines)) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 69 | $exit = 1; |
| 70 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 71 | @rawlines = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | exit($exit); |
| 76 | |
| 77 | sub top_of_kernel_tree { |
| 78 | if ((-f "COPYING") && (-f "CREDITS") && (-f "Kbuild") && |
| 79 | (-f "MAINTAINERS") && (-f "Makefile") && (-f "README") && |
| 80 | (-d "Documentation") && (-d "arch") && (-d "include") && |
| 81 | (-d "drivers") && (-d "fs") && (-d "init") && (-d "ipc") && |
| 82 | (-d "kernel") && (-d "lib") && (-d "scripts")) { |
| 83 | return 1; |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | sub expand_tabs { |
| 89 | my ($str) = @_; |
| 90 | |
| 91 | my $res = ''; |
| 92 | my $n = 0; |
| 93 | for my $c (split(//, $str)) { |
| 94 | if ($c eq "\t") { |
| 95 | $res .= ' '; |
| 96 | $n++; |
| 97 | for (; ($n % 8) != 0; $n++) { |
| 98 | $res .= ' '; |
| 99 | } |
| 100 | next; |
| 101 | } |
| 102 | $res .= $c; |
| 103 | $n++; |
| 104 | } |
| 105 | |
| 106 | return $res; |
| 107 | } |
| 108 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 109 | sub line_stats { |
| 110 | my ($line) = @_; |
| 111 | |
| 112 | # Drop the diff line leader and expand tabs |
| 113 | $line =~ s/^.//; |
| 114 | $line = expand_tabs($line); |
| 115 | |
| 116 | # Pick the indent from the front of the line. |
| 117 | my ($white) = ($line =~ /^(\s*)/); |
| 118 | |
| 119 | return (length($line), length($white)); |
| 120 | } |
| 121 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 122 | sub sanitise_line { |
| 123 | my ($line) = @_; |
| 124 | |
| 125 | my $res = ''; |
| 126 | my $l = ''; |
| 127 | |
| 128 | my $quote = ''; |
| 129 | |
| 130 | foreach my $c (split(//, $line)) { |
| 131 | if ($l ne "\\" && ($c eq "'" || $c eq '"')) { |
| 132 | if ($quote eq '') { |
| 133 | $quote = $c; |
| 134 | $res .= $c; |
| 135 | $l = $c; |
| 136 | next; |
| 137 | } elsif ($quote eq $c) { |
| 138 | $quote = ''; |
| 139 | } |
| 140 | } |
| 141 | if ($quote && $c ne "\t") { |
| 142 | $res .= "X"; |
| 143 | } else { |
| 144 | $res .= $c; |
| 145 | } |
| 146 | |
| 147 | $l = $c; |
| 148 | } |
| 149 | |
| 150 | return $res; |
| 151 | } |
| 152 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 153 | sub ctx_block_get { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 154 | my ($linenr, $remain, $outer, $open, $close, $off) = @_; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 155 | my $line; |
| 156 | my $start = $linenr - 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 157 | my $blk = ''; |
| 158 | my @o; |
| 159 | my @c; |
| 160 | my @res = (); |
| 161 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 162 | my $level = 0; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 163 | for ($line = $start; $remain > 0; $line++) { |
| 164 | next if ($rawlines[$line] =~ /^-/); |
| 165 | $remain--; |
| 166 | |
| 167 | $blk .= $rawlines[$line]; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 168 | foreach my $c (split(//, $rawlines[$line])) { |
| 169 | ##print "C<$c>L<$level><$open$close>O<$off>\n"; |
| 170 | if ($off > 0) { |
| 171 | $off--; |
| 172 | next; |
| 173 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 174 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 175 | if ($c eq $close && $level > 0) { |
| 176 | $level--; |
| 177 | last if ($level == 0); |
| 178 | } elsif ($c eq $open) { |
| 179 | $level++; |
| 180 | } |
| 181 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 182 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 183 | if (!$outer || $level <= 1) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 184 | push(@res, $rawlines[$line]); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 187 | last if ($level == 0); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 190 | return ($level, @res); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 191 | } |
| 192 | sub ctx_block_outer { |
| 193 | my ($linenr, $remain) = @_; |
| 194 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 195 | my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0); |
| 196 | return @r; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 197 | } |
| 198 | sub ctx_block { |
| 199 | my ($linenr, $remain) = @_; |
| 200 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 201 | my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0); |
| 202 | return @r; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 203 | } |
| 204 | sub ctx_statement { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 205 | my ($linenr, $remain, $off) = @_; |
| 206 | |
| 207 | my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off); |
| 208 | return @r; |
| 209 | } |
| 210 | sub ctx_block_level { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 211 | my ($linenr, $remain) = @_; |
| 212 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 213 | return ctx_block_get($linenr, $remain, 0, '{', '}', 0); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 214 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 215 | sub ctx_statement_level { |
| 216 | my ($linenr, $remain, $off) = @_; |
| 217 | |
| 218 | return ctx_block_get($linenr, $remain, 0, '(', ')', $off); |
| 219 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 220 | |
| 221 | sub ctx_locate_comment { |
| 222 | my ($first_line, $end_line) = @_; |
| 223 | |
| 224 | # Catch a comment on the end of the line itself. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 225 | my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 226 | return $current_comment if (defined $current_comment); |
| 227 | |
| 228 | # Look through the context and try and figure out if there is a |
| 229 | # comment. |
| 230 | my $in_comment = 0; |
| 231 | $current_comment = ''; |
| 232 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 233 | my $line = $rawlines[$linenr - 1]; |
| 234 | #warn " $line\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 235 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
| 236 | $in_comment = 1; |
| 237 | } |
| 238 | if ($line =~ m@/\*@) { |
| 239 | $in_comment = 1; |
| 240 | } |
| 241 | if (!$in_comment && $current_comment ne '') { |
| 242 | $current_comment = ''; |
| 243 | } |
| 244 | $current_comment .= $line . "\n" if ($in_comment); |
| 245 | if ($line =~ m@\*/@) { |
| 246 | $in_comment = 0; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | chomp($current_comment); |
| 251 | return($current_comment); |
| 252 | } |
| 253 | sub ctx_has_comment { |
| 254 | my ($first_line, $end_line) = @_; |
| 255 | my $cmt = ctx_locate_comment($first_line, $end_line); |
| 256 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 257 | ##print "LINE: $rawlines[$end_line - 1 ]\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 258 | ##print "CMMT: $cmt\n"; |
| 259 | |
| 260 | return ($cmt ne ''); |
| 261 | } |
| 262 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 263 | sub ctx_expr_before { |
| 264 | my ($line) = @_; |
| 265 | |
| 266 | ##print "CHECK<$line>\n"; |
| 267 | |
| 268 | my $pos = length($line) - 1; |
| 269 | my $count = 0; |
| 270 | my $c; |
| 271 | |
| 272 | for (; $pos >= 0; $pos--) { |
| 273 | $c = substr($line, $pos, 1); |
| 274 | ##print "CHECK: c<$c> count<$count>\n"; |
| 275 | if ($c eq ')') { |
| 276 | $count++; |
| 277 | } elsif ($c eq '(') { |
| 278 | last if (--$count == 0); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | ##print "CHECK: result<" . substr($line, 0, $pos) . ">\n"; |
| 283 | |
| 284 | return substr($line, 0, $pos); |
| 285 | } |
| 286 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 287 | sub cat_vet { |
| 288 | my ($vet) = @_; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 289 | my ($res, $coded); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 290 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 291 | $res = ''; |
| 292 | while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]])/g) { |
| 293 | $coded = sprintf("^%c", unpack('C', $2) + 64); |
| 294 | $res .= $1 . $coded; |
| 295 | } |
| 296 | $res =~ s/$/\$/; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 297 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 298 | return $res; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 301 | my @report = (); |
| 302 | sub report { |
| 303 | push(@report, $_[0]); |
| 304 | } |
| 305 | sub report_dump { |
| 306 | @report; |
| 307 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 308 | sub ERROR { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 309 | report("ERROR: $_[0]\n"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 310 | our $clean = 0; |
| 311 | } |
| 312 | sub WARN { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 313 | report("WARNING: $_[0]\n"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 314 | our $clean = 0; |
| 315 | } |
| 316 | sub CHK { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 317 | report("CHECK: $_[0]\n"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 318 | our $clean = 0; |
| 319 | } |
| 320 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 321 | sub process { |
| 322 | my $filename = shift; |
| 323 | my @lines = @_; |
| 324 | |
| 325 | my $linenr=0; |
| 326 | my $prevline=""; |
| 327 | my $stashline=""; |
| 328 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 329 | my $length; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 330 | my $indent; |
| 331 | my $previndent=0; |
| 332 | my $stashindent=0; |
| 333 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 334 | our $clean = 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 335 | my $signoff = 0; |
| 336 | my $is_patch = 0; |
| 337 | |
| 338 | # Trace the real file/line as we go. |
| 339 | my $realfile = ''; |
| 340 | my $realline = 0; |
| 341 | my $realcnt = 0; |
| 342 | my $here = ''; |
| 343 | my $in_comment = 0; |
| 344 | my $first_line = 0; |
| 345 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 346 | my $Ident = qr{[A-Za-z\d_]+}; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 347 | my $Storage = qr{extern|static|asmlinkage}; |
| 348 | my $Sparse = qr{ |
| 349 | __user| |
| 350 | __kernel| |
| 351 | __force| |
| 352 | __iomem| |
| 353 | __must_check| |
| 354 | __init_refok| |
| 355 | fastcall |
| 356 | }x; |
| 357 | my $Inline = qr{inline|__always_inline|noinline}; |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 358 | my $NonptrType = qr{ |
| 359 | \b |
| 360 | (?:const\s+)? |
| 361 | (?:unsigned\s+)? |
| 362 | (?: |
| 363 | void| |
| 364 | char| |
| 365 | short| |
| 366 | int| |
| 367 | long| |
| 368 | unsigned| |
| 369 | float| |
| 370 | double| |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 371 | bool| |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 372 | long\s+int| |
| 373 | long\s+long| |
| 374 | long\s+long\s+int| |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 375 | u8|u16|u32|u64| |
| 376 | s8|s16|s32|s64| |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 377 | struct\s+$Ident| |
| 378 | union\s+$Ident| |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 379 | enum\s+$Ident| |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 380 | ${Ident}_t |
| 381 | ) |
| 382 | (?:\s+$Sparse)* |
| 383 | \b |
| 384 | }x; |
| 385 | my $Type = qr{ |
| 386 | \b$NonptrType\b |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 387 | (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? |
| 388 | (?:\s+$Sparse)* |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 389 | }x; |
| 390 | my $Declare = qr{(?:$Storage\s+)?$Type}; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 391 | my $Attribute = qr{ |
| 392 | const| |
| 393 | __read_mostly| |
| 394 | __(?:mem|cpu|dev|)(?:initdata|init) |
| 395 | }x; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 396 | my $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; |
| 397 | my $Lval = qr{$Ident(?:$Member)*}; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 398 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 399 | # Possible bare types. |
| 400 | my @bare = (); |
| 401 | my $Bare = $NonptrType; |
| 402 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 403 | # Pre-scan the patch looking for any __setup documentation. |
| 404 | my @setup_docs = (); |
| 405 | my $setup_docs = 0; |
| 406 | foreach my $line (@lines) { |
| 407 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 408 | $setup_docs = 0; |
| 409 | if ($1 =~ m@Documentation/kernel-parameters.txt$@) { |
| 410 | $setup_docs = 1; |
| 411 | } |
| 412 | next; |
| 413 | } |
| 414 | |
| 415 | if ($setup_docs && $line =~ /^\+/) { |
| 416 | push(@setup_docs, $line); |
| 417 | } |
| 418 | } |
| 419 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 420 | foreach my $line (@lines) { |
| 421 | $linenr++; |
| 422 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 423 | my $rawline = $line; |
| 424 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 425 | #extract the filename as it passes |
| 426 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 427 | $realfile=$1; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 428 | $realfile =~ s@^[^/]*/@@; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 429 | $in_comment = 0; |
| 430 | next; |
| 431 | } |
| 432 | #extract the line range in the file after the patch is applied |
| 433 | if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) { |
| 434 | $is_patch = 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 435 | $first_line = $linenr + 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 436 | $in_comment = 0; |
| 437 | $realline=$1-1; |
| 438 | if (defined $2) { |
| 439 | $realcnt=$3+1; |
| 440 | } else { |
| 441 | $realcnt=1+1; |
| 442 | } |
| 443 | next; |
| 444 | } |
| 445 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 446 | # track the line number as we move through the hunk, note that |
| 447 | # new versions of GNU diff omit the leading space on completely |
| 448 | # blank context lines so we need to count that too. |
| 449 | if ($line =~ /^( |\+|$)/) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 450 | $realline++; |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 451 | $realcnt-- if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 452 | |
| 453 | # track any sort of multi-line comment. Obviously if |
| 454 | # the added text or context do not include the whole |
| 455 | # comment we will not see it. Such is life. |
| 456 | # |
| 457 | # Guestimate if this is a continuing comment. If this |
| 458 | # is the start of a diff block and this line starts |
| 459 | # ' *' then it is very likely a comment. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 460 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 461 | $in_comment = 1; |
| 462 | } |
| 463 | if ($line =~ m@/\*@) { |
| 464 | $in_comment = 1; |
| 465 | } |
| 466 | if ($line =~ m@\*/@) { |
| 467 | $in_comment = 0; |
| 468 | } |
| 469 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 470 | # Measure the line length and indent. |
| 471 | ($length, $indent) = line_stats($line); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 472 | |
| 473 | # Track the previous line. |
| 474 | ($prevline, $stashline) = ($stashline, $line); |
| 475 | ($previndent, $stashindent) = ($stashindent, $indent); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 476 | } elsif ($realcnt == 1) { |
| 477 | $realcnt--; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | #make up the handle for any error we report on this line |
Randy Dunlap | 389834b | 2007-06-08 13:47:03 -0700 | [diff] [blame] | 481 | $here = "#$linenr: "; |
| 482 | $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 483 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 484 | my $hereline = "$here\n$line\n"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 485 | my $herecurr = "$here\n$line\n"; |
| 486 | my $hereprev = "$here\n$prevline\n$line\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 487 | |
| 488 | #check the patch for a signoff: |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 489 | if ($line =~ /^\s*signed-off-by:/i) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 490 | # This is a signoff, if ugly, so do not double report. |
| 491 | $signoff++; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 492 | if (!($line =~ /^\s*Signed-off-by:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 493 | WARN("Signed-off-by: is the preferred form\n" . |
| 494 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 495 | } |
| 496 | if ($line =~ /^\s*signed-off-by:\S/i) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 497 | WARN("need space after Signed-off-by:\n" . |
| 498 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 502 | # Check for wrappage within a valid hunk of the file |
| 503 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 504 | ERROR("patch seems to be corrupt (line wrapped?)\n" . |
| 505 | $herecurr); |
| 506 | } |
| 507 | |
| 508 | # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php |
| 509 | if (($realfile =~ /^$/ || $line =~ /^\+/) && |
| 510 | !($line =~ m/^( |
| 511 | [\x09\x0A\x0D\x20-\x7E] # ASCII |
| 512 | | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte |
| 513 | | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs |
| 514 | | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte |
| 515 | | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates |
| 516 | | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 517 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 518 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 519 | )*$/x )) { |
| 520 | ERROR("Invalid UTF-8\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 521 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 522 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 523 | #ignore lines being removed |
| 524 | if ($line=~/^-/) {next;} |
| 525 | |
| 526 | # check we are in a valid source file if not then ignore this hunk |
| 527 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 528 | |
| 529 | #trailing whitespace |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 530 | if ($line =~ /^\+.*\015/) { |
| 531 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 532 | ERROR("DOS line endings\n" . $herevet); |
| 533 | |
| 534 | } elsif ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 535 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 536 | ERROR("trailing whitespace\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 537 | } |
| 538 | #80 column limit |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 539 | if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 540 | WARN("line over 80 characters\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | # check we are in a valid source file *.[hc] if not then ignore this hunk |
| 544 | next if ($realfile !~ /\.[hc]$/); |
| 545 | |
| 546 | # at the beginning of a line any tabs must come first and anything |
| 547 | # more than 8 must use tabs. |
| 548 | if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 549 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 550 | ERROR("use tabs not spaces\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 553 | # Remove comments from the line before processing. |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 554 | my $comment_edge = ($line =~ s@/\*.*\*/@@g) + |
| 555 | ($line =~ s@/\*.*@@) + |
| 556 | ($line =~ s@^(.).*\*/@$1@); |
| 557 | |
| 558 | # The rest of our checks refer specifically to C style |
| 559 | # only apply those _outside_ comments. Only skip |
| 560 | # lines in the middle of comments. |
| 561 | next if (!$comment_edge && $in_comment); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 562 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 563 | # Standardise the strings and chars within the input to simplify matching. |
| 564 | $line = sanitise_line($line); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 565 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 566 | # Check for potential 'bare' types |
| 567 | if ($realcnt && |
| 568 | $line !~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?$Type\b/ && |
| 569 | $line !~ /$Ident:\s*$/ && |
| 570 | $line !~ /^.\s*$Ident\s*\(/ && |
| 571 | ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?($Ident)\b/ || |
| 572 | $line =~ /^.\s*(?:$Storage\s+)?($Ident)\b\s*\**\s*$Ident\s*(?:;|=)/)) { |
| 573 | my $possible = $1; |
| 574 | if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ && |
| 575 | $possible ne 'goto' && $possible ne 'return' && |
| 576 | $possible ne 'struct' && $possible ne 'enum' && |
| 577 | $possible ne 'case' && $possible ne 'else' && |
| 578 | $possible ne 'typedef') { |
| 579 | #print "POSSIBLE<$possible>\n"; |
| 580 | push(@bare, $possible); |
| 581 | my $bare = join("|", @bare); |
| 582 | $Bare = qr{ |
| 583 | \b(?:$bare)\b |
| 584 | (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? |
| 585 | (?:\s+$Sparse)* |
| 586 | }x; |
| 587 | } |
| 588 | } |
| 589 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 590 | # |
| 591 | # Checks which may be anchored in the context. |
| 592 | # |
| 593 | |
| 594 | # Check for switch () and associated case and default |
| 595 | # statements should be at the same indent. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 596 | if ($line=~/\bswitch\s*\(.*\)/) { |
| 597 | my $err = ''; |
| 598 | my $sep = ''; |
| 599 | my @ctx = ctx_block_outer($linenr, $realcnt); |
| 600 | shift(@ctx); |
| 601 | for my $ctx (@ctx) { |
| 602 | my ($clen, $cindent) = line_stats($ctx); |
| 603 | if ($ctx =~ /^\+\s*(case\s+|default:)/ && |
| 604 | $indent != $cindent) { |
| 605 | $err .= "$sep$ctx\n"; |
| 606 | $sep = ''; |
| 607 | } else { |
| 608 | $sep = "[...]\n"; |
| 609 | } |
| 610 | } |
| 611 | if ($err ne '') { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 612 | ERROR("switch and case should be at the same indent\n$hereline$err"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
| 616 | # if/while/etc brace do not go on next line, unless defining a do while loop, |
| 617 | # or if that brace on the next line is for something else |
| 618 | if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 619 | my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 620 | my $ctx_ln = $linenr + $#ctx + 1; |
| 621 | my $ctx_cnt = $realcnt - $#ctx - 1; |
| 622 | my $ctx = join("\n", @ctx); |
| 623 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 624 | # Skip over any removed lines in the context following statement. |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 625 | while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) { |
| 626 | $ctx_ln++; |
| 627 | $ctx_cnt--; |
| 628 | } |
| 629 | ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>"; |
| 630 | |
| 631 | if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 632 | ERROR("That open brace { should be on the previous line\n" . |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 633 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 634 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 635 | if ($level == 0 && $ctx =~ /\)\s*\;\s*$/ && defined $lines[$ctx_ln - 1]) { |
| 636 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); |
| 637 | if ($nindent > $indent) { |
| 638 | WARN("Trailing semicolon indicates no statements, indent implies otherwise\n" . |
| 639 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
| 640 | } |
| 641 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | #ignore lines not being added |
| 645 | if ($line=~/^[^\+]/) {next;} |
| 646 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 647 | # TEST: allow direct testing of the type matcher. |
| 648 | if ($tst_type && $line =~ /^.$Declare$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 649 | ERROR("TEST: is type $Declare\n" . $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 650 | next; |
| 651 | } |
| 652 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 653 | # check for initialisation to aggregates open brace on the next line |
| 654 | if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ && |
| 655 | $line =~ /^.\s*{/) { |
| 656 | ERROR("That open brace { should be on the previous line\n" . $hereprev); |
| 657 | } |
| 658 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 659 | # |
| 660 | # Checks which are anchored on the added line. |
| 661 | # |
| 662 | |
| 663 | # check for malformed paths in #include statements (uses RAW line) |
| 664 | if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) { |
| 665 | my $path = $1; |
| 666 | if ($path =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 667 | ERROR("malformed #include filename\n" . |
| 668 | $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 669 | } |
| 670 | # Sanitise this special form of string. |
| 671 | $path = 'X' x length($path); |
| 672 | $line =~ s{\<.*\>}{<$path>}; |
| 673 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 674 | |
| 675 | # no C99 // comments |
| 676 | if ($line =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 677 | ERROR("do not use C99 // comments\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 678 | } |
| 679 | # Remove C99 comments. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 680 | $line =~ s@//.*@@; |
| 681 | |
| 682 | #EXPORT_SYMBOL should immediately follow its function closing }. |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 683 | if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) || |
| 684 | ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { |
| 685 | my $name = $1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 686 | if (($prevline !~ /^}/) && |
| 687 | ($prevline !~ /^\+}/) && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 688 | ($prevline !~ /^ }/) && |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 689 | ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=)/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 690 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 694 | # check for external initialisers. |
| 695 | if ($line =~ /^.$Type\s*$Ident\s*=\s*(0|NULL);/) { |
| 696 | ERROR("do not initialise externals to 0 or NULL\n" . |
| 697 | $herecurr); |
| 698 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 699 | # check for static initialisers. |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 700 | if ($line =~ /\s*static\s.*=\s*(0|NULL);/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 701 | ERROR("do not initialise statics to 0 or NULL\n" . |
| 702 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 705 | # check for new typedefs, only function parameters and sparse annotations |
| 706 | # make sense. |
| 707 | if ($line =~ /\btypedef\s/ && |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 708 | $line !~ /\btypedef\s+$Type\s+\(\s*\*?$Ident\s*\)\s*\(/ && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 709 | $line !~ /\b__bitwise(?:__|)\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 710 | WARN("do not add new typedefs\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | # * goes on variable not on type |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 714 | if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 715 | ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" . |
| 716 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 717 | |
| 718 | } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 719 | ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . |
| 720 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 721 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 722 | } elsif ($line =~ m{$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 723 | ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . |
| 724 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 725 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 726 | } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 727 | ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . |
| 728 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | # # no BUG() or BUG_ON() |
| 732 | # if ($line =~ /\b(BUG|BUG_ON)\b/) { |
| 733 | # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n"; |
| 734 | # print "$herecurr"; |
| 735 | # $clean = 0; |
| 736 | # } |
| 737 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 738 | # printk should use KERN_* levels. Note that follow on printk's on the |
| 739 | # same line do not need a level, so we use the current block context |
| 740 | # to try and find and validate the current printk. In summary the current |
| 741 | # printk includes all preceeding printk's which have no newline on the end. |
| 742 | # we assume the first bad printk is the one to report. |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 743 | if ($line =~ /\bprintk\((?!KERN_)\s*"/) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 744 | my $ok = 0; |
| 745 | for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { |
| 746 | #print "CHECK<$lines[$ln - 1]\n"; |
| 747 | # we have a preceeding printk if it ends |
| 748 | # with "\n" ignore it, else it is to blame |
| 749 | if ($lines[$ln - 1] =~ m{\bprintk\(}) { |
| 750 | if ($rawlines[$ln - 1] !~ m{\\n"}) { |
| 751 | $ok = 1; |
| 752 | } |
| 753 | last; |
| 754 | } |
| 755 | } |
| 756 | if ($ok == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 757 | WARN("printk() should include KERN_ facility level\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 758 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 761 | # function brace can't be on same line, except for #defines of do while, |
| 762 | # or if closed on same line |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 763 | if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 764 | !($line=~/\#define.*do\s{/) and !($line=~/}/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 765 | ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 766 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 767 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 768 | # check for spaces between functions and their parentheses. |
| 769 | if ($line =~ /($Ident)\s+\(/ && |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 770 | $1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright)$/ && |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 771 | $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 772 | WARN("no space between function name and open parenthesis '('\n" . $herecurr); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 773 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 774 | # Check operator spacing. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 775 | # Note we expand the line with the leading + as the real |
| 776 | # line will be displayed with the leading + and the tabs |
| 777 | # will therefore also expand that way. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 778 | my $opline = $line; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 779 | $opline = expand_tabs($opline); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 780 | $opline =~ s/^./ /; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 781 | if (!($line=~/\#\s*include/)) { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 782 | my $ops = qr{ |
| 783 | <<=|>>=|<=|>=|==|!=| |
| 784 | \+=|-=|\*=|\/=|%=|\^=|\|=|&=| |
| 785 | =>|->|<<|>>|<|>|=|!|~| |
| 786 | &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/ |
| 787 | }x; |
| 788 | my @elements = split(/($ops|;)/, $opline); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 789 | my $off = 0; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 790 | for (my $n = 0; $n < $#elements; $n += 2) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 791 | $off += length($elements[$n]); |
| 792 | |
| 793 | my $a = ''; |
| 794 | $a = 'V' if ($elements[$n] ne ''); |
| 795 | $a = 'W' if ($elements[$n] =~ /\s$/); |
| 796 | $a = 'B' if ($elements[$n] =~ /(\[|\()$/); |
| 797 | $a = 'O' if ($elements[$n] eq ''); |
| 798 | $a = 'E' if ($elements[$n] eq '' && $n == 0); |
| 799 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 800 | my $op = $elements[$n + 1]; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 801 | |
| 802 | my $c = ''; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 803 | if (defined $elements[$n + 2]) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 804 | $c = 'V' if ($elements[$n + 2] ne ''); |
| 805 | $c = 'W' if ($elements[$n + 2] =~ /^\s/); |
| 806 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); |
| 807 | $c = 'O' if ($elements[$n + 2] eq ''); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 808 | $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 809 | } else { |
| 810 | $c = 'E'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 813 | # Pick up the preceeding and succeeding characters. |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 814 | my $ca = substr($opline, 0, $off); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 815 | my $cc = ''; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 816 | if (length($opline) >= ($off + length($elements[$n + 1]))) { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 817 | $cc = substr($opline, $off + length($elements[$n + 1])); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 818 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 819 | my $cb = "$ca$;$cc"; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 820 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 821 | my $ctx = "${a}x${c}"; |
| 822 | |
| 823 | my $at = "(ctx:$ctx)"; |
| 824 | |
| 825 | my $ptr = (" " x $off) . "^"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 826 | my $hereptr = "$hereline$ptr\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 827 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 828 | # Classify operators into binary, unary, or |
| 829 | # definitions (* only) where they have more |
| 830 | # than one mode. |
| 831 | my $unary_ctx = $prevline . $ca; |
| 832 | $unary_ctx =~ s/^./ /; |
| 833 | my $is_unary = 0; |
| 834 | my $Unary = qr{ |
| 835 | (?: |
| 836 | ^|;|,|$ops|\(|\?|:| |
| 837 | \(\s*$Type\s*\)| |
| 838 | $Type| |
| 839 | return|case|else| |
| 840 | \{|\}| |
| 841 | \[| |
| 842 | ^.\#\s*define\s+$Ident\s*(?:\([^\)]*\))?| |
| 843 | ^.\#\s*else| |
| 844 | ^.\#\s*endif| |
| 845 | ^.\#\s*(?:if|ifndef|ifdef)\b.* |
| 846 | )\s*(?:|\\)\s*$ |
| 847 | }x; |
| 848 | my $UnaryFalse = qr{ |
| 849 | sizeof\s*\(\s*$Type\s*\)\s*$ |
| 850 | }x; |
| 851 | my $UnaryDefine = qr{ |
| 852 | (?:$Type|$Bare)\s*| |
| 853 | (?:$Type|$Bare).*,\s*\** |
| 854 | }x; |
| 855 | if ($op eq '-' || $op eq '&' || $op eq '*') { |
| 856 | # An operator is binary if the left hand |
| 857 | # side is a value. Pick out the known |
| 858 | # non-values. |
| 859 | if ($unary_ctx =~ /$Unary$/s && |
| 860 | $unary_ctx !~ /$UnaryFalse$/s) { |
| 861 | $is_unary = 1; |
| 862 | |
| 863 | # Special handling for ')' check if this |
| 864 | # brace represents a conditional, if so |
| 865 | # we are unary. |
| 866 | } elsif ($unary_ctx =~ /\)\s*$/) { |
| 867 | my $before = ctx_expr_before($unary_ctx); |
| 868 | if ($before =~ /(?:for|if|while)\s*$/) { |
| 869 | $is_unary = 1; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | # Check for type definition for of '*'. |
| 874 | if ($op eq '*' && $unary_ctx =~ /$UnaryDefine$/) { |
| 875 | $is_unary = 2; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | #if ($op eq '-' || $op eq '&' || $op eq '*') { |
| 880 | # print "UNARY: <$is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n"; |
| 881 | #} |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 882 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 883 | # ; should have either the end of line or a space or \ after it |
| 884 | if ($op eq ';') { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 885 | if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ && |
| 886 | $cc !~ /^;/) { |
| 887 | ERROR("need space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | # // is a comment |
| 891 | } elsif ($op eq '//') { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 892 | |
| 893 | # -> should have no spaces |
| 894 | } elsif ($op eq '->') { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 895 | if ($ctx =~ /Wx.|.xW/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 896 | ERROR("no spaces around that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | # , must have a space on the right. |
| 900 | } elsif ($op eq ',') { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 901 | if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 902 | ERROR("need space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 905 | # '*' as part of a type definition -- reported already. |
| 906 | } elsif ($op eq '*' && $is_unary == 2) { |
| 907 | #warn "'*' is part of type\n"; |
| 908 | |
| 909 | # unary operators should have a space before and |
| 910 | # none after. May be left adjacent to another |
| 911 | # unary operator, or a cast |
| 912 | } elsif ($op eq '!' || $op eq '~' || |
| 913 | ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) { |
| 914 | if ($ctx !~ /[WEB]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 915 | ERROR("need space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 916 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 917 | if ($ctx =~ /.xW/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 918 | ERROR("no space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | # unary ++ and unary -- are allowed no space on one side. |
| 922 | } elsif ($op eq '++' or $op eq '--') { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 923 | if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 924 | ERROR("need space one side of that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 925 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 926 | if ($ctx =~ /Wx./ && $cc =~ /^;/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 927 | ERROR("no space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 928 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 929 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 930 | # << and >> may either have or not have spaces both sides |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 931 | } elsif ($op eq '<<' or $op eq '>>' or |
| 932 | $op eq '&' or $op eq '^' or $op eq '|' or |
| 933 | $op eq '+' or $op eq '-' or |
| 934 | $op eq '*' or $op eq '/') |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 935 | { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 936 | if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 937 | ERROR("need consistent spacing around '$op' $at\n" . |
| 938 | $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | # All the others need spaces both sides. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 942 | } elsif ($ctx !~ /[EW]x[WE]/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 943 | # Ignore email addresses <foo@bar> |
| 944 | if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) && |
| 945 | !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) { |
| 946 | ERROR("need spaces around that '$op' $at\n" . $hereptr); |
| 947 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 948 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 949 | $off += length($elements[$n + 1]); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 953 | # check for multiple assignments |
| 954 | if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { |
| 955 | WARN("multiple assignments should be avoided\n" . $herecurr); |
| 956 | } |
| 957 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 958 | ## # check for multiple declarations, allowing for a function declaration |
| 959 | ## # continuation. |
| 960 | ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ && |
| 961 | ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { |
| 962 | ## |
| 963 | ## # Remove any bracketed sections to ensure we do not |
| 964 | ## # falsly report the parameters of functions. |
| 965 | ## my $ln = $line; |
| 966 | ## while ($ln =~ s/\([^\(\)]*\)//g) { |
| 967 | ## } |
| 968 | ## if ($ln =~ /,/) { |
| 969 | ## WARN("declaring multiple variables together should be avoided\n" . $herecurr); |
| 970 | ## } |
| 971 | ## } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 972 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 973 | #need space before brace following if, while, etc |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 974 | if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || |
| 975 | $line =~ /do{/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 976 | ERROR("need a space before the open brace '{'\n" . $herecurr); |
| 977 | } |
| 978 | |
| 979 | # closing brace should have a space following it when it has anything |
| 980 | # on the line |
| 981 | if ($line =~ /}(?!(?:,|;|\)))\S/) { |
| 982 | ERROR("need a space after that close brace '}'\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 985 | # check spacing on square brackets |
| 986 | if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { |
| 987 | ERROR("no space after that open square bracket '['\n" . $herecurr); |
| 988 | } |
| 989 | if ($line =~ /\s\]/) { |
| 990 | ERROR("no space before that close square bracket ']'\n" . $herecurr); |
| 991 | } |
| 992 | |
| 993 | # check spacing on paretheses |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 994 | if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && |
| 995 | $line !~ /for\s*\(\s+;/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 996 | ERROR("no space after that open parenthesis '('\n" . $herecurr); |
| 997 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 998 | if ($line =~ /\s\)/ && $line !~ /^.\s*\)/ && |
| 999 | $line !~ /for\s*\(.*;\s+\)/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1000 | ERROR("no space before that close parenthesis ')'\n" . $herecurr); |
| 1001 | } |
| 1002 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1003 | #goto labels aren't indented, allow a single space however |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1004 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1005 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1006 | WARN("labels should not be indented\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | # Need a space before open parenthesis after if, while etc |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1010 | if ($line=~/\b(if|while|for|switch)\(/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1011 | ERROR("need a space before the open parenthesis '('\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | # Check for illegal assignment in if conditional. |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1015 | if ($line=~/\bif\s*\(.*[^<>!=]=[^=].*\)/) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1016 | #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1017 | ERROR("do not use assignment in if condition\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | # Check for }<nl>else {, these must be at the same |
| 1021 | # indent level to be relevant to each other. |
| 1022 | if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and |
| 1023 | $previndent == $indent) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1024 | ERROR("else should follow close brace '}'\n" . $hereprev); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1027 | #studly caps, commented out until figure out how to distinguish between use of existing and adding new |
| 1028 | # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { |
| 1029 | # print "No studly caps, use _\n"; |
| 1030 | # print "$herecurr"; |
| 1031 | # $clean = 0; |
| 1032 | # } |
| 1033 | |
| 1034 | #no spaces allowed after \ in define |
| 1035 | if ($line=~/\#define.*\\\s$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1036 | WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1039 | #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) |
| 1040 | if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1041 | my $checkfile = "include/linux/$1.h"; |
| 1042 | if (-f $checkfile) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1043 | CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" . |
| 1044 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1048 | # if and else should not have general statements after it |
| 1049 | if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ && |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1050 | $1 !~ /^\s*(?:\sif|{|\\|$)/) { |
| 1051 | ERROR("trailing statements should be on next line\n" . $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1054 | # multi-statement macros should be enclosed in a do while loop, grab the |
| 1055 | # first statement and ensure its the whole macro if its not enclosed |
| 1056 | # in a known goot container |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1057 | if ($prevline =~ /\#define.*\\/ && |
| 1058 | $prevline !~/(?:do\s+{|\(\{|\{)/ && |
| 1059 | $line !~ /(?:do\s+{|\(\{|\{)/ && |
| 1060 | $line !~ /^.\s*$Declare\s/) { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1061 | # Grab the first statement, if that is the entire macro |
| 1062 | # its ok. This may start either on the #define line |
| 1063 | # or the one below. |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1064 | my $ln = $linenr; |
| 1065 | my $cnt = $realcnt; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1066 | my $off = 0; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1067 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1068 | # If the macro starts on the define line start |
| 1069 | # grabbing the statement after the identifier |
| 1070 | $prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$}; |
| 1071 | ##print "1<$1> 2<$2>\n"; |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1072 | if (defined $2 && $2 ne '') { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1073 | $off = length($1); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1074 | $ln--; |
| 1075 | $cnt++; |
| 1076 | } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1077 | my @ctx = ctx_statement($ln, $cnt, $off); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1078 | my $ctx_ln = $ln + $#ctx + 1; |
| 1079 | my $ctx = join("\n", @ctx); |
| 1080 | |
| 1081 | # Pull in any empty extension lines. |
| 1082 | while ($ctx =~ /\\$/ && |
| 1083 | $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) { |
| 1084 | $ctx .= $lines[$ctx_ln - 1]; |
| 1085 | $ctx_ln++; |
| 1086 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1087 | |
| 1088 | if ($ctx =~ /\\$/) { |
| 1089 | if ($ctx =~ /;/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1090 | ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n"); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1091 | } else { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1092 | ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n"); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1093 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1094 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1097 | # check for redundant bracing round if etc |
| 1098 | if ($line =~ /\b(if|while|for|else)\b/) { |
| 1099 | # Locate the end of the opening statement. |
| 1100 | my @control = ctx_statement($linenr, $realcnt, 0); |
| 1101 | my $nr = $linenr + (scalar(@control) - 1); |
| 1102 | my $cnt = $realcnt - (scalar(@control) - 1); |
| 1103 | |
| 1104 | my $off = $realcnt - $cnt; |
| 1105 | #print "$off: line<$line>end<" . $lines[$nr - 1] . ">\n"; |
| 1106 | |
| 1107 | # If this is is a braced statement group check it |
| 1108 | if ($lines[$nr - 1] =~ /{\s*$/) { |
| 1109 | my ($lvl, @block) = ctx_block_level($nr, $cnt); |
| 1110 | |
| 1111 | my $stmt = join(' ', @block); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1112 | $stmt =~ s/(^[^{]*){//; |
| 1113 | my $before = $1; |
| 1114 | $stmt =~ s/}([^}]*$)//; |
| 1115 | my $after = $1; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1116 | |
| 1117 | #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n"; |
| 1118 | #print "stmt<$stmt>\n\n"; |
| 1119 | |
| 1120 | # Count the ;'s if there is fewer than two |
| 1121 | # then there can only be one statement, |
| 1122 | # if there is a brace inside we cannot |
| 1123 | # trivially detect if its one statement. |
| 1124 | # Also nested if's often require braces to |
| 1125 | # disambiguate the else binding so shhh there. |
| 1126 | my @semi = ($stmt =~ /;/g); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1127 | push(@semi, "/**/") if ($stmt =~ m@/\*@); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1128 | ##print "semi<" . scalar(@semi) . ">\n"; |
| 1129 | if ($lvl == 0 && scalar(@semi) < 2 && |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1130 | $stmt !~ /{/ && $stmt !~ /\bif\b/ && |
| 1131 | $before !~ /}/ && $after !~ /{/) { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1132 | my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n"; |
| 1133 | shift(@block); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1134 | WARN("braces {} are not necessary for single statement blocks\n" . $herectx); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1139 | # don't include deprecated include files (uses RAW line) |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1140 | for my $inc (@dep_includes) { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1141 | if ($rawline =~ m@\#\s*include\s*\<$inc>@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1142 | ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1146 | # don't use deprecated functions |
| 1147 | for my $func (@dep_functions) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1148 | if ($line =~ /\b$func\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1149 | ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | # no volatiles please |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1154 | if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1155 | WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1158 | # SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated |
| 1159 | if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) { |
| 1160 | ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr); |
| 1161 | } |
| 1162 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1163 | # warn about #if 0 |
| 1164 | if ($line =~ /^.#\s*if\s+0\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1165 | CHK("if this code is redundant consider removing it\n" . |
| 1166 | $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1169 | # check for needless kfree() checks |
| 1170 | if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { |
| 1171 | my $expr = $1; |
| 1172 | if ($line =~ /\bkfree\(\Q$expr\E\);/) { |
| 1173 | WARN("kfree(NULL) is safe this check is probabally not required\n" . $hereprev); |
| 1174 | } |
| 1175 | } |
| 1176 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1177 | # warn about #ifdefs in C files |
| 1178 | # if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { |
| 1179 | # print "#ifdef in C files should be avoided\n"; |
| 1180 | # print "$herecurr"; |
| 1181 | # $clean = 0; |
| 1182 | # } |
| 1183 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1184 | # warn about spacing in #ifdefs |
| 1185 | if ($line =~ /^.#\s*(ifdef|ifndef|elif)\s\s+/) { |
| 1186 | ERROR("exactly one space required after that #$1\n" . $herecurr); |
| 1187 | } |
| 1188 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1189 | # check for spinlock_t definitions without a comment. |
| 1190 | if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { |
| 1191 | my $which = $1; |
| 1192 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1193 | CHK("$1 definition without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | # check for memory barriers without a comment. |
| 1197 | if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { |
| 1198 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1199 | CHK("memory barrier without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | # check of hardware specific defines |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1203 | if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1204 | CHK("architecture specific defines should be avoided\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1205 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1206 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1207 | # check the location of the inline attribute, that it is between |
| 1208 | # storage class and type. |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1209 | if ($line =~ /\b$Type\s+$Inline\b/ || |
| 1210 | $line =~ /\b$Inline\s+$Storage\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1211 | ERROR("inline keyword should sit between storage class and type\n" . $herecurr); |
| 1212 | } |
| 1213 | |
| 1214 | # check for new externs in .c files. |
| 1215 | if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) { |
| 1216 | WARN("externs should be avoided in .c files\n" . $herecurr); |
| 1217 | } |
| 1218 | |
| 1219 | # checks for new __setup's |
| 1220 | if ($rawline =~ /\b__setup\("([^"]*)"/) { |
| 1221 | my $name = $1; |
| 1222 | |
| 1223 | if (!grep(/$name/, @setup_docs)) { |
| 1224 | CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); |
| 1225 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1226 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1227 | |
| 1228 | # check for pointless casting of kmalloc return |
| 1229 | if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { |
| 1230 | WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); |
| 1231 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | if ($chk_patch && !$is_patch) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1235 | ERROR("Does not appear to be a unified-diff format patch\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1236 | } |
| 1237 | if ($is_patch && $chk_signoff && $signoff == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1238 | ERROR("Missing Signed-off-by: line(s)\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1241 | if ($clean == 0 && ($chk_patch || $is_patch)) { |
| 1242 | print report_dump(); |
| 1243 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1244 | if ($clean == 1 && $quiet == 0) { |
| 1245 | print "Your patch has no obvious style problems and is ready for submission.\n" |
| 1246 | } |
| 1247 | if ($clean == 0 && $quiet == 0) { |
| 1248 | print "Your patch has style problems, please review. If any of these errors\n"; |
| 1249 | print "are false positives report them to the maintainer, see\n"; |
| 1250 | print "CHECKPATCH in MAINTAINERS.\n"; |
| 1251 | } |
| 1252 | return $clean; |
| 1253 | } |