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 | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 12 | my $V = '0.07'; |
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>) { |
| 50 | if (/^Files:\s+(.*\S)/) { |
| 51 | for my $file (split(/[, ]+/, $1)) { |
| 52 | if ($file =~ m@include/(.*)@) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 53 | push(@dep_includes, $1); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 56 | |
| 57 | } elsif (/^Funcs:\s+(.*\S)/) { |
| 58 | for my $func (split(/[, ]+/, $1)) { |
| 59 | push(@dep_functions, $func); |
| 60 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 65 | my @rawlines = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 66 | while (<>) { |
| 67 | chomp; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 68 | push(@rawlines, $_); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 69 | if (eof(ARGV)) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 70 | if (!process($ARGV, @rawlines)) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 71 | $exit = 1; |
| 72 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 73 | @rawlines = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | exit($exit); |
| 78 | |
| 79 | sub top_of_kernel_tree { |
| 80 | if ((-f "COPYING") && (-f "CREDITS") && (-f "Kbuild") && |
| 81 | (-f "MAINTAINERS") && (-f "Makefile") && (-f "README") && |
| 82 | (-d "Documentation") && (-d "arch") && (-d "include") && |
| 83 | (-d "drivers") && (-d "fs") && (-d "init") && (-d "ipc") && |
| 84 | (-d "kernel") && (-d "lib") && (-d "scripts")) { |
| 85 | return 1; |
| 86 | } |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | sub expand_tabs { |
| 91 | my ($str) = @_; |
| 92 | |
| 93 | my $res = ''; |
| 94 | my $n = 0; |
| 95 | for my $c (split(//, $str)) { |
| 96 | if ($c eq "\t") { |
| 97 | $res .= ' '; |
| 98 | $n++; |
| 99 | for (; ($n % 8) != 0; $n++) { |
| 100 | $res .= ' '; |
| 101 | } |
| 102 | next; |
| 103 | } |
| 104 | $res .= $c; |
| 105 | $n++; |
| 106 | } |
| 107 | |
| 108 | return $res; |
| 109 | } |
| 110 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 111 | sub line_stats { |
| 112 | my ($line) = @_; |
| 113 | |
| 114 | # Drop the diff line leader and expand tabs |
| 115 | $line =~ s/^.//; |
| 116 | $line = expand_tabs($line); |
| 117 | |
| 118 | # Pick the indent from the front of the line. |
| 119 | my ($white) = ($line =~ /^(\s*)/); |
| 120 | |
| 121 | return (length($line), length($white)); |
| 122 | } |
| 123 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 124 | sub sanitise_line { |
| 125 | my ($line) = @_; |
| 126 | |
| 127 | my $res = ''; |
| 128 | my $l = ''; |
| 129 | |
| 130 | my $quote = ''; |
| 131 | |
| 132 | foreach my $c (split(//, $line)) { |
| 133 | if ($l ne "\\" && ($c eq "'" || $c eq '"')) { |
| 134 | if ($quote eq '') { |
| 135 | $quote = $c; |
| 136 | $res .= $c; |
| 137 | $l = $c; |
| 138 | next; |
| 139 | } elsif ($quote eq $c) { |
| 140 | $quote = ''; |
| 141 | } |
| 142 | } |
| 143 | if ($quote && $c ne "\t") { |
| 144 | $res .= "X"; |
| 145 | } else { |
| 146 | $res .= $c; |
| 147 | } |
| 148 | |
| 149 | $l = $c; |
| 150 | } |
| 151 | |
| 152 | return $res; |
| 153 | } |
| 154 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 155 | sub ctx_block_get { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 156 | my ($linenr, $remain, $outer, $open, $close) = @_; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 157 | my $line; |
| 158 | my $start = $linenr - 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 159 | my $blk = ''; |
| 160 | my @o; |
| 161 | my @c; |
| 162 | my @res = (); |
| 163 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 164 | for ($line = $start; $remain > 0; $line++) { |
| 165 | next if ($rawlines[$line] =~ /^-/); |
| 166 | $remain--; |
| 167 | |
| 168 | $blk .= $rawlines[$line]; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 169 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 170 | @o = ($blk =~ /$open/g); |
| 171 | @c = ($blk =~ /$close/g); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 172 | |
| 173 | if (!$outer || (scalar(@o) - scalar(@c)) == 1) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 174 | push(@res, $rawlines[$line]); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | last if (scalar(@o) == scalar(@c)); |
| 178 | } |
| 179 | |
| 180 | return @res; |
| 181 | } |
| 182 | sub ctx_block_outer { |
| 183 | my ($linenr, $remain) = @_; |
| 184 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 185 | return ctx_block_get($linenr, $remain, 1, '\{', '\}'); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 186 | } |
| 187 | sub ctx_block { |
| 188 | my ($linenr, $remain) = @_; |
| 189 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 190 | return ctx_block_get($linenr, $remain, 0, '\{', '\}'); |
| 191 | } |
| 192 | sub ctx_statement { |
| 193 | my ($linenr, $remain) = @_; |
| 194 | |
| 195 | return ctx_block_get($linenr, $remain, 0, '\(', '\)'); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | sub ctx_locate_comment { |
| 199 | my ($first_line, $end_line) = @_; |
| 200 | |
| 201 | # Catch a comment on the end of the line itself. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 202 | my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 203 | return $current_comment if (defined $current_comment); |
| 204 | |
| 205 | # Look through the context and try and figure out if there is a |
| 206 | # comment. |
| 207 | my $in_comment = 0; |
| 208 | $current_comment = ''; |
| 209 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 210 | my $line = $rawlines[$linenr - 1]; |
| 211 | #warn " $line\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 212 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
| 213 | $in_comment = 1; |
| 214 | } |
| 215 | if ($line =~ m@/\*@) { |
| 216 | $in_comment = 1; |
| 217 | } |
| 218 | if (!$in_comment && $current_comment ne '') { |
| 219 | $current_comment = ''; |
| 220 | } |
| 221 | $current_comment .= $line . "\n" if ($in_comment); |
| 222 | if ($line =~ m@\*/@) { |
| 223 | $in_comment = 0; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | chomp($current_comment); |
| 228 | return($current_comment); |
| 229 | } |
| 230 | sub ctx_has_comment { |
| 231 | my ($first_line, $end_line) = @_; |
| 232 | my $cmt = ctx_locate_comment($first_line, $end_line); |
| 233 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 234 | ##print "LINE: $rawlines[$end_line - 1 ]\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 235 | ##print "CMMT: $cmt\n"; |
| 236 | |
| 237 | return ($cmt ne ''); |
| 238 | } |
| 239 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 240 | sub cat_vet { |
| 241 | my ($vet) = @_; |
| 242 | |
| 243 | $vet =~ s/\t/^I/; |
| 244 | $vet =~ s/$/\$/; |
| 245 | |
| 246 | return $vet; |
| 247 | } |
| 248 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 249 | sub ERROR { |
| 250 | print "ERROR: $_[0]\n"; |
| 251 | our $clean = 0; |
| 252 | } |
| 253 | sub WARN { |
| 254 | print "WARNING: $_[0]\n"; |
| 255 | our $clean = 0; |
| 256 | } |
| 257 | sub CHK { |
| 258 | print "CHECK: $_[0]\n"; |
| 259 | our $clean = 0; |
| 260 | } |
| 261 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 262 | sub process { |
| 263 | my $filename = shift; |
| 264 | my @lines = @_; |
| 265 | |
| 266 | my $linenr=0; |
| 267 | my $prevline=""; |
| 268 | my $stashline=""; |
| 269 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 270 | my $length; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 271 | my $indent; |
| 272 | my $previndent=0; |
| 273 | my $stashindent=0; |
| 274 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 275 | our $clean = 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 276 | my $signoff = 0; |
| 277 | my $is_patch = 0; |
| 278 | |
| 279 | # Trace the real file/line as we go. |
| 280 | my $realfile = ''; |
| 281 | my $realline = 0; |
| 282 | my $realcnt = 0; |
| 283 | my $here = ''; |
| 284 | my $in_comment = 0; |
| 285 | my $first_line = 0; |
| 286 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 287 | my $Ident = qr{[A-Za-z\d_]+}; |
| 288 | my $Storage = qr{extern|static}; |
| 289 | my $Sparse = qr{__user|__kernel|__force|__iomem}; |
| 290 | my $NonptrType = qr{ |
| 291 | \b |
| 292 | (?:const\s+)? |
| 293 | (?:unsigned\s+)? |
| 294 | (?: |
| 295 | void| |
| 296 | char| |
| 297 | short| |
| 298 | int| |
| 299 | long| |
| 300 | unsigned| |
| 301 | float| |
| 302 | double| |
| 303 | long\s+int| |
| 304 | long\s+long| |
| 305 | long\s+long\s+int| |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 306 | u8|u16|u32|u64| |
| 307 | s8|s16|s32|s64| |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 308 | struct\s+$Ident| |
| 309 | union\s+$Ident| |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 310 | enum\s+$Ident| |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 311 | ${Ident}_t |
| 312 | ) |
| 313 | (?:\s+$Sparse)* |
| 314 | \b |
| 315 | }x; |
| 316 | my $Type = qr{ |
| 317 | \b$NonptrType\b |
| 318 | (?:\s*\*+\s*const|\s*\*+)? |
| 319 | }x; |
| 320 | my $Declare = qr{(?:$Storage\s+)?$Type}; |
| 321 | my $Attribute = qr{__read_mostly|__init|__initdata}; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 322 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 323 | # Pre-scan the patch looking for any __setup documentation. |
| 324 | my @setup_docs = (); |
| 325 | my $setup_docs = 0; |
| 326 | foreach my $line (@lines) { |
| 327 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 328 | $setup_docs = 0; |
| 329 | if ($1 =~ m@Documentation/kernel-parameters.txt$@) { |
| 330 | $setup_docs = 1; |
| 331 | } |
| 332 | next; |
| 333 | } |
| 334 | |
| 335 | if ($setup_docs && $line =~ /^\+/) { |
| 336 | push(@setup_docs, $line); |
| 337 | } |
| 338 | } |
| 339 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 340 | foreach my $line (@lines) { |
| 341 | $linenr++; |
| 342 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 343 | my $rawline = $line; |
| 344 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 345 | #extract the filename as it passes |
| 346 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 347 | $realfile=$1; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 348 | $realfile =~ s@^[^/]*/@@; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 349 | $in_comment = 0; |
| 350 | next; |
| 351 | } |
| 352 | #extract the line range in the file after the patch is applied |
| 353 | if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) { |
| 354 | $is_patch = 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 355 | $first_line = $linenr + 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 356 | $in_comment = 0; |
| 357 | $realline=$1-1; |
| 358 | if (defined $2) { |
| 359 | $realcnt=$3+1; |
| 360 | } else { |
| 361 | $realcnt=1+1; |
| 362 | } |
| 363 | next; |
| 364 | } |
| 365 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 366 | # track the line number as we move through the hunk, note that |
| 367 | # new versions of GNU diff omit the leading space on completely |
| 368 | # blank context lines so we need to count that too. |
| 369 | if ($line =~ /^( |\+|$)/) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 370 | $realline++; |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 371 | $realcnt-- if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 372 | |
| 373 | # track any sort of multi-line comment. Obviously if |
| 374 | # the added text or context do not include the whole |
| 375 | # comment we will not see it. Such is life. |
| 376 | # |
| 377 | # Guestimate if this is a continuing comment. If this |
| 378 | # is the start of a diff block and this line starts |
| 379 | # ' *' then it is very likely a comment. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 380 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 381 | $in_comment = 1; |
| 382 | } |
| 383 | if ($line =~ m@/\*@) { |
| 384 | $in_comment = 1; |
| 385 | } |
| 386 | if ($line =~ m@\*/@) { |
| 387 | $in_comment = 0; |
| 388 | } |
| 389 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 390 | # Measure the line length and indent. |
| 391 | ($length, $indent) = line_stats($line); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 392 | |
| 393 | # Track the previous line. |
| 394 | ($prevline, $stashline) = ($stashline, $line); |
| 395 | ($previndent, $stashindent) = ($stashindent, $indent); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 396 | } elsif ($realcnt == 1) { |
| 397 | $realcnt--; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | #make up the handle for any error we report on this line |
Randy Dunlap | 389834b | 2007-06-08 13:47:03 -0700 | [diff] [blame] | 401 | $here = "#$linenr: "; |
| 402 | $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 403 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 404 | my $hereline = "$here\n$line\n"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 405 | my $herecurr = "$here\n$line\n"; |
| 406 | my $hereprev = "$here\n$prevline\n$line\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 407 | |
| 408 | #check the patch for a signoff: |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 409 | if ($line =~ /^\s*signed-off-by:/i) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 410 | # This is a signoff, if ugly, so do not double report. |
| 411 | $signoff++; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 412 | if (!($line =~ /^\s*Signed-off-by:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 413 | WARN("Signed-off-by: is the preferred form\n" . |
| 414 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 415 | } |
| 416 | if ($line =~ /^\s*signed-off-by:\S/i) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 417 | WARN("need space after Signed-off-by:\n" . |
| 418 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 422 | # Check for wrappage within a valid hunk of the file |
| 423 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 424 | ERROR("patch seems to be corrupt (line wrapped?)\n" . |
| 425 | $herecurr); |
| 426 | } |
| 427 | |
| 428 | # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php |
| 429 | if (($realfile =~ /^$/ || $line =~ /^\+/) && |
| 430 | !($line =~ m/^( |
| 431 | [\x09\x0A\x0D\x20-\x7E] # ASCII |
| 432 | | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte |
| 433 | | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs |
| 434 | | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte |
| 435 | | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates |
| 436 | | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 437 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 438 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 439 | )*$/x )) { |
| 440 | ERROR("Invalid UTF-8\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 441 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 442 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 443 | #ignore lines being removed |
| 444 | if ($line=~/^-/) {next;} |
| 445 | |
| 446 | # check we are in a valid source file if not then ignore this hunk |
| 447 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 448 | |
| 449 | #trailing whitespace |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 450 | if ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 451 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 452 | ERROR("trailing whitespace\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 453 | } |
| 454 | #80 column limit |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 455 | if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 456 | WARN("line over 80 characters\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | # check we are in a valid source file *.[hc] if not then ignore this hunk |
| 460 | next if ($realfile !~ /\.[hc]$/); |
| 461 | |
| 462 | # at the beginning of a line any tabs must come first and anything |
| 463 | # more than 8 must use tabs. |
| 464 | if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 465 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 466 | ERROR("use tabs not spaces\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | # |
| 470 | # The rest of our checks refer specifically to C style |
| 471 | # only apply those _outside_ comments. |
| 472 | # |
| 473 | next if ($in_comment); |
| 474 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 475 | # Remove comments from the line before processing. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 476 | $line =~ s@/\*.*\*/@@g; |
| 477 | $line =~ s@/\*.*@@; |
| 478 | $line =~ s@.*\*/@@; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 479 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 480 | # Standardise the strings and chars within the input to simplify matching. |
| 481 | $line = sanitise_line($line); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 482 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 483 | # |
| 484 | # Checks which may be anchored in the context. |
| 485 | # |
| 486 | |
| 487 | # Check for switch () and associated case and default |
| 488 | # statements should be at the same indent. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 489 | if ($line=~/\bswitch\s*\(.*\)/) { |
| 490 | my $err = ''; |
| 491 | my $sep = ''; |
| 492 | my @ctx = ctx_block_outer($linenr, $realcnt); |
| 493 | shift(@ctx); |
| 494 | for my $ctx (@ctx) { |
| 495 | my ($clen, $cindent) = line_stats($ctx); |
| 496 | if ($ctx =~ /^\+\s*(case\s+|default:)/ && |
| 497 | $indent != $cindent) { |
| 498 | $err .= "$sep$ctx\n"; |
| 499 | $sep = ''; |
| 500 | } else { |
| 501 | $sep = "[...]\n"; |
| 502 | } |
| 503 | } |
| 504 | if ($err ne '') { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 505 | ERROR("switch and case should be at the same indent\n$hereline\n$err\n"); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | # if/while/etc brace do not go on next line, unless defining a do while loop, |
| 510 | # or if that brace on the next line is for something else |
| 511 | if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) { |
| 512 | my @ctx = ctx_statement($linenr, $realcnt); |
| 513 | my $ctx_ln = $linenr + $#ctx + 1; |
| 514 | my $ctx_cnt = $realcnt - $#ctx - 1; |
| 515 | my $ctx = join("\n", @ctx); |
| 516 | |
| 517 | while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) { |
| 518 | $ctx_ln++; |
| 519 | $ctx_cnt--; |
| 520 | } |
| 521 | ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>"; |
| 522 | |
| 523 | if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { |
| 524 | ERROR("That { should be on the previous line\n" . |
| 525 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| 529 | #ignore lines not being added |
| 530 | if ($line=~/^[^\+]/) {next;} |
| 531 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 532 | # TEST: allow direct testing of the type matcher. |
| 533 | if ($tst_type && $line =~ /^.$Declare$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 534 | ERROR("TEST: is type $Declare\n" . $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 535 | next; |
| 536 | } |
| 537 | |
| 538 | # |
| 539 | # Checks which are anchored on the added line. |
| 540 | # |
| 541 | |
| 542 | # check for malformed paths in #include statements (uses RAW line) |
| 543 | if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) { |
| 544 | my $path = $1; |
| 545 | if ($path =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 546 | ERROR("malformed #include filename\n" . |
| 547 | $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 548 | } |
| 549 | # Sanitise this special form of string. |
| 550 | $path = 'X' x length($path); |
| 551 | $line =~ s{\<.*\>}{<$path>}; |
| 552 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 553 | |
| 554 | # no C99 // comments |
| 555 | if ($line =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 556 | ERROR("do not use C99 // comments\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 557 | } |
| 558 | # Remove C99 comments. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 559 | $line =~ s@//.*@@; |
| 560 | |
| 561 | #EXPORT_SYMBOL should immediately follow its function closing }. |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 562 | if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) || |
| 563 | ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { |
| 564 | my $name = $1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 565 | if (($prevline !~ /^}/) && |
| 566 | ($prevline !~ /^\+}/) && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 567 | ($prevline !~ /^ }/) && |
| 568 | ($prevline !~ /\s$name(?:\s+$Attribute)?\s*(?:;|=)/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 569 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 573 | # check for static initialisers. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 574 | if ($line=~/\s*static\s.*=\s+(0|NULL);/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 575 | ERROR("do not initialise statics to 0 or NULL\n" . |
| 576 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 579 | # check for new typedefs, only function parameters and sparse annotations |
| 580 | # make sense. |
| 581 | if ($line =~ /\btypedef\s/ && |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 582 | $line !~ /\btypedef\s+$Type\s+\(\s*\*$Ident\s*\)\s*\(/ && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 583 | $line !~ /\b__bitwise(?:__|)\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 584 | WARN("do not add new typedefs\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | # * goes on variable not on type |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 588 | if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 589 | ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" . |
| 590 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 591 | |
| 592 | } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 593 | ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . |
| 594 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 595 | |
| 596 | } elsif ($line =~ m{$NonptrType(\*+)(?:\s+const)?\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 597 | ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . |
| 598 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 599 | |
| 600 | } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+const)\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 601 | ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . |
| 602 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | # # no BUG() or BUG_ON() |
| 606 | # if ($line =~ /\b(BUG|BUG_ON)\b/) { |
| 607 | # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n"; |
| 608 | # print "$herecurr"; |
| 609 | # $clean = 0; |
| 610 | # } |
| 611 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 612 | # printk should use KERN_* levels. Note that follow on printk's on the |
| 613 | # same line do not need a level, so we use the current block context |
| 614 | # to try and find and validate the current printk. In summary the current |
| 615 | # printk includes all preceeding printk's which have no newline on the end. |
| 616 | # we assume the first bad printk is the one to report. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 617 | if ($line =~ /\bprintk\((?!KERN_)/) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 618 | my $ok = 0; |
| 619 | for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { |
| 620 | #print "CHECK<$lines[$ln - 1]\n"; |
| 621 | # we have a preceeding printk if it ends |
| 622 | # with "\n" ignore it, else it is to blame |
| 623 | if ($lines[$ln - 1] =~ m{\bprintk\(}) { |
| 624 | if ($rawlines[$ln - 1] !~ m{\\n"}) { |
| 625 | $ok = 1; |
| 626 | } |
| 627 | last; |
| 628 | } |
| 629 | } |
| 630 | if ($ok == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 631 | WARN("printk() should include KERN_ facility level\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 632 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 635 | # function brace can't be on same line, except for #defines of do while, |
| 636 | # or if closed on same line |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 637 | if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 638 | !($line=~/\#define.*do\s{/) and !($line=~/}/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 639 | 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] | 640 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 641 | |
| 642 | # Check operator spacing. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 643 | # Note we expand the line with the leading + as the real |
| 644 | # line will be displayed with the leading + and the tabs |
| 645 | # will therefore also expand that way. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 646 | my $opline = $line; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 647 | $opline = expand_tabs($opline); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 648 | $opline =~ s/^./ /; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 649 | if (!($line=~/\#\s*include/)) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 650 | my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 651 | my $off = 0; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 652 | for (my $n = 0; $n < $#elements; $n += 2) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 653 | $off += length($elements[$n]); |
| 654 | |
| 655 | my $a = ''; |
| 656 | $a = 'V' if ($elements[$n] ne ''); |
| 657 | $a = 'W' if ($elements[$n] =~ /\s$/); |
| 658 | $a = 'B' if ($elements[$n] =~ /(\[|\()$/); |
| 659 | $a = 'O' if ($elements[$n] eq ''); |
| 660 | $a = 'E' if ($elements[$n] eq '' && $n == 0); |
| 661 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 662 | my $op = $elements[$n + 1]; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 663 | |
| 664 | my $c = ''; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 665 | if (defined $elements[$n + 2]) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 666 | $c = 'V' if ($elements[$n + 2] ne ''); |
| 667 | $c = 'W' if ($elements[$n + 2] =~ /^\s/); |
| 668 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); |
| 669 | $c = 'O' if ($elements[$n + 2] eq ''); |
| 670 | } else { |
| 671 | $c = 'E'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 674 | # Pick up the preceeding and succeeding characters. |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 675 | my $ca = substr($opline, 0, $off); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 676 | my $cc = ''; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 677 | if (length($opline) >= ($off + length($elements[$n + 1]))) { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 678 | $cc = substr($opline, $off + length($elements[$n + 1])); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 679 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 680 | my $cb = "$ca$;$cc"; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 681 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 682 | my $ctx = "${a}x${c}"; |
| 683 | |
| 684 | my $at = "(ctx:$ctx)"; |
| 685 | |
| 686 | my $ptr = (" " x $off) . "^"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 687 | my $hereptr = "$hereline$ptr\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 688 | |
| 689 | ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 690 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 691 | # ; should have either the end of line or a space or \ after it |
| 692 | if ($op eq ';') { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 693 | if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ && |
| 694 | $cc !~ /^;/) { |
| 695 | ERROR("need space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | # // is a comment |
| 699 | } elsif ($op eq '//') { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 700 | |
| 701 | # -> should have no spaces |
| 702 | } elsif ($op eq '->') { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 703 | if ($ctx =~ /Wx.|.xW/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 704 | ERROR("no spaces around that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | # , must have a space on the right. |
| 708 | } elsif ($op eq ',') { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 709 | if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 710 | ERROR("need space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | # unary ! and unary ~ are allowed no space on the right |
| 714 | } elsif ($op eq '!' or $op eq '~') { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 715 | if ($ctx !~ /[WOEB]x./) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 716 | ERROR("need space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 717 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 718 | if ($ctx =~ /.xW/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 719 | ERROR("no space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | # unary ++ and unary -- are allowed no space on one side. |
| 723 | } elsif ($op eq '++' or $op eq '--') { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 724 | if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 725 | ERROR("need space one side of that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 726 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 727 | if ($ctx =~ /Wx./ && $cc =~ /^;/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 728 | ERROR("no space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 729 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 730 | |
| 731 | # & is both unary and binary |
| 732 | # unary: |
| 733 | # a &b |
| 734 | # binary (consistent spacing): |
| 735 | # a&b OK |
| 736 | # a & b OK |
| 737 | # |
| 738 | # boiling down to: if there is a space on the right then there |
| 739 | # should be one on the left. |
| 740 | # |
| 741 | # - is the same |
| 742 | # |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 743 | } elsif ($op eq '&' or $op eq '-') { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 744 | if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 745 | ERROR("need space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 748 | # * is the same as & only adding: |
| 749 | # type: |
| 750 | # (foo *) |
| 751 | # (foo **) |
| 752 | # |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 753 | } elsif ($op eq '*') { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 754 | if ($ca !~ /$Type$/ && $cb !~ /(\*$;|$;\*)/ && |
| 755 | $ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB|BxB/) { |
| 756 | ERROR("need space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | # << and >> may either have or not have spaces both sides |
| 760 | } elsif ($op eq '<<' or $op eq '>>' or $op eq '+' or $op eq '/' or |
| 761 | $op eq '^' or $op eq '|') |
| 762 | { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 763 | if ($ctx !~ /VxV|WxW|VxE|WxE/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 764 | ERROR("need consistent spacing around '$op' $at\n" . |
| 765 | $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | # All the others need spaces both sides. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 769 | } elsif ($ctx !~ /[EW]x[WE]/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 770 | ERROR("need spaces around that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 771 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 772 | $off += length($elements[$n + 1]); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | |
| 776 | #need space before brace following if, while, etc |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 777 | if ($line =~ /\(.*\){/ || $line =~ /do{/) { |
| 778 | ERROR("need a space before the open brace '{'\n" . $herecurr); |
| 779 | } |
| 780 | |
| 781 | # closing brace should have a space following it when it has anything |
| 782 | # on the line |
| 783 | if ($line =~ /}(?!(?:,|;|\)))\S/) { |
| 784 | ERROR("need a space after that close brace '}'\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | #goto labels aren't indented, allow a single space however |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 788 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 789 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 790 | WARN("labels should not be indented\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | # Need a space before open parenthesis after if, while etc |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 794 | if ($line=~/\b(if|while|for|switch)\(/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 795 | ERROR("need a space before the open parenthesis '('\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | # Check for illegal assignment in if conditional. |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 799 | if ($line=~/\bif\s*\(.*[^<>!=]=[^=].*\)/) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 800 | #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 801 | ERROR("do not use assignment in if condition\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | # Check for }<nl>else {, these must be at the same |
| 805 | # indent level to be relevant to each other. |
| 806 | if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and |
| 807 | $previndent == $indent) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 808 | ERROR("else should follow close brace '}'\n" . $hereprev); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 811 | #studly caps, commented out until figure out how to distinguish between use of existing and adding new |
| 812 | # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { |
| 813 | # print "No studly caps, use _\n"; |
| 814 | # print "$herecurr"; |
| 815 | # $clean = 0; |
| 816 | # } |
| 817 | |
| 818 | #no spaces allowed after \ in define |
| 819 | if ($line=~/\#define.*\\\s$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 820 | WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 823 | #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) |
| 824 | if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 825 | my $checkfile = "include/linux/$1.h"; |
| 826 | if (-f $checkfile) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 827 | CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" . |
| 828 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 832 | # if and else should not have general statements after it |
| 833 | if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ && |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 834 | $1 !~ /^\s*(?:\sif|{|\\|$)/) { |
| 835 | ERROR("trailing statements should be on next line\n" . $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 838 | # multi-statement macros should be enclosed in a do while loop, grab the |
| 839 | # first statement and ensure its the whole macro if its not enclosed |
| 840 | # in a known goot container |
| 841 | if (($prevline=~/\#define.*\\/) and |
| 842 | !($prevline=~/do\s+{/) and !($prevline=~/\(\{/) and |
| 843 | !($line=~/do.*{/) and !($line=~/\(\{/) and |
| 844 | !($line=~/^.\s*$Declare\s/)) { |
| 845 | # Grab the first statement, if that is the entire macro |
| 846 | # its ok. This may start either on the #define line |
| 847 | # or the one below. |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 848 | my $ln = $linenr; |
| 849 | my $cnt = $realcnt; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 850 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 851 | # If the macro starts on the define line start there. |
| 852 | if ($prevline !~ m{^.#\s*define\s*$Ident(?:\([^\)]*\))?\s*\\\s*$}) { |
| 853 | $ln--; |
| 854 | $cnt++; |
| 855 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 856 | my @ctx = ctx_statement($ln, $cnt); |
| 857 | my $ctx_ln = $ln + $#ctx + 1; |
| 858 | my $ctx = join("\n", @ctx); |
| 859 | |
| 860 | # Pull in any empty extension lines. |
| 861 | while ($ctx =~ /\\$/ && |
| 862 | $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) { |
| 863 | $ctx .= $lines[$ctx_ln - 1]; |
| 864 | $ctx_ln++; |
| 865 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 866 | |
| 867 | if ($ctx =~ /\\$/) { |
| 868 | if ($ctx =~ /;/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 869 | 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] | 870 | } else { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 871 | 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] | 872 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 873 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 876 | # don't include deprecated include files (uses RAW line) |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 877 | for my $inc (@dep_includes) { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 878 | if ($rawline =~ m@\#\s*include\s*\<$inc>@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 879 | 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] | 880 | } |
| 881 | } |
| 882 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 883 | # don't use deprecated functions |
| 884 | for my $func (@dep_functions) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 885 | if ($line =~ /\b$func\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 886 | 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] | 887 | } |
| 888 | } |
| 889 | |
| 890 | # no volatiles please |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 891 | if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 892 | 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] | 893 | } |
| 894 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 895 | # warn about #if 0 |
| 896 | if ($line =~ /^.#\s*if\s+0\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 897 | CHK("if this code is redundant consider removing it\n" . |
| 898 | $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 901 | # warn about #ifdefs in C files |
| 902 | # if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { |
| 903 | # print "#ifdef in C files should be avoided\n"; |
| 904 | # print "$herecurr"; |
| 905 | # $clean = 0; |
| 906 | # } |
| 907 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 908 | # check for spinlock_t definitions without a comment. |
| 909 | if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { |
| 910 | my $which = $1; |
| 911 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 912 | CHK("$1 definition without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | # check for memory barriers without a comment. |
| 916 | if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { |
| 917 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 918 | CHK("memory barrier without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | # check of hardware specific defines |
| 922 | if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 923 | CHK("architecture specific defines should be avoided\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 924 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 925 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 926 | # check the location of the inline attribute, that it is between |
| 927 | # storage class and type. |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 928 | if ($line =~ /$Type\s+(?:inline|__always_inline)\b/ || |
| 929 | $line =~ /\b(?:inline|always_inline)\s+$Storage/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 930 | ERROR("inline keyword should sit between storage class and type\n" . $herecurr); |
| 931 | } |
| 932 | |
| 933 | # check for new externs in .c files. |
| 934 | if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) { |
| 935 | WARN("externs should be avoided in .c files\n" . $herecurr); |
| 936 | } |
| 937 | |
| 938 | # checks for new __setup's |
| 939 | if ($rawline =~ /\b__setup\("([^"]*)"/) { |
| 940 | my $name = $1; |
| 941 | |
| 942 | if (!grep(/$name/, @setup_docs)) { |
| 943 | CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); |
| 944 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 945 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | if ($chk_patch && !$is_patch) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 949 | ERROR("Does not appear to be a unified-diff format patch\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 950 | } |
| 951 | if ($is_patch && $chk_signoff && $signoff == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 952 | ERROR("Missing Signed-off-by: line(s)\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | if ($clean == 1 && $quiet == 0) { |
| 956 | print "Your patch has no obvious style problems and is ready for submission.\n" |
| 957 | } |
| 958 | if ($clean == 0 && $quiet == 0) { |
| 959 | print "Your patch has style problems, please review. If any of these errors\n"; |
| 960 | print "are false positives report them to the maintainer, see\n"; |
| 961 | print "CHECKPATCH in MAINTAINERS.\n"; |
| 962 | } |
| 963 | return $clean; |
| 964 | } |