3566 lines · 95.2 KB · Perl
RawDownload
		$linenr++; 		my $rawline = $rawlines[$linenr - 1]; #extract the line range in the file after the patch is applied		if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {			$is_patch = 1;			$first_line = $linenr + 1;			$realline=$1-1;			if (defined $2) {				$realcnt=$3+1;			} else {				$realcnt=1+1;			}			annotate_reset();			$prev_values = 'E'; 			%suppress_ifbraces = ();			%suppress_whiletrailers = ();			%suppress_export = ();			$suppress_statement = 0;			next; # track the line number as we move through the hunk, note that# new versions of GNU diff omit the leading space on completely# blank context lines so we need to count that too.		} elsif ($line =~ /^( |\+|$)/) {			$realline++;			$realcnt-- if ($realcnt != 0); 			# Measure the line length and indent.			($length, $indent) = line_stats($rawline); 			# Track the previous line.			($prevline, $stashline) = ($stashline, $line);			($previndent, $stashindent) = ($stashindent, $indent);			($prevrawline, $stashrawline) = ($stashrawline, $rawline); 			#warn "line<$line>\n"; 		} elsif ($realcnt == 1) {			$realcnt--;		} 		my $hunk_line = ($realcnt != 0); #make up the handle for any error we report on this line		$prefix = "$filename:$realline: " if ($emacs && $file);		$prefix = "$filename:$linenr: " if ($emacs && !$file); 		$here = "#$linenr: " if (!$file);		$here = "#$realline: " if ($file); 		# extract the filename as it passes		if ($line =~ /^diff --git.*?(\S+)$/) {			$realfile = $1;			$realfile =~ s@^([^/]*)/@@;			$in_commit_log = 0;		} elsif ($line =~ /^\+\+\+\s+(\S+)/) {			$realfile = $1;			$realfile =~ s@^([^/]*)/@@;			$in_commit_log = 0; 			$p1_prefix = $1;			if (!$file && $tree && $p1_prefix ne '' &&			    -e "$root/$p1_prefix") {				WARN("PATCH_PREFIX",				     "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");			} 			if ($realfile =~ m@^include/asm/@) {				ERROR("MODIFIED_INCLUDE_ASM",				      "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");			}			next;		} 		$here .= "FILE: $realfile:$realline:" if ($realcnt != 0); 		my $hereline = "$here\n$rawline\n";		my $herecurr = "$here\n$rawline\n";		my $hereprev = "$here\n$prevrawline\n$rawline\n"; 		$cnt_lines++ if ($realcnt != 0); # Check for incorrect file permissions		if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {			my $permhere = $here . "FILE: $realfile\n";			if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {				ERROR("EXECUTE_PERMISSIONS",				      "do not set execute permissions for source files\n" . $permhere);			}		} # Check the patch for a signoff:		if ($line =~ /^\s*signed-off-by:/i) {			$signoff++;			$in_commit_log = 0;		} # Check signature styles		if (!$in_header_lines &&		    $line =~ /^(\s*)($signature_tags)(\s*)(.*)/) {			my $space_before = $1;			my $sign_off = $2;			my $space_after = $3;			my $email = $4;			my $ucfirst_sign_off = ucfirst(lc($sign_off)); 			if (defined $space_before && $space_before ne "") {				WARN("BAD_SIGN_OFF",				     "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr);			}			if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {				WARN("BAD_SIGN_OFF",				     "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr);			}			if (!defined $space_after || $space_after ne " ") {				WARN("BAD_SIGN_OFF",				     "Use a single space after $ucfirst_sign_off\n" . $herecurr);			} 			my ($email_name, $email_address, $comment) = parse_email($email);			my $suggested_email = format_email(($email_name, $email_address));			if ($suggested_email eq "") {				ERROR("BAD_SIGN_OFF",				      "Unrecognized email address: '$email'\n" . $herecurr);			} else {				my $dequoted = $suggested_email;				$dequoted =~ s/^"//;				$dequoted =~ s/" </ </;				# Don't force email to have quotes				# Allow just an angle bracketed address				if ("$dequoted$comment" ne $email &&				    "<$email_address>$comment" ne $email &&				    "$suggested_email$comment" ne $email) {					WARN("BAD_SIGN_OFF",					     "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);				}			}		} # Check for wrappage within a valid hunk of the file		if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {			ERROR("CORRUPTED_PATCH",			      "patch seems to be corrupt (line wrapped?)\n" .				$herecurr) if (!$emitted_corrupt++);		} # Check for absolute kernel paths.		if ($tree) {			while ($line =~ m{(?:^|\s)(/\S*)}g) {				my $file = $1; 				if ($file =~ m{^(.*?)(?::\d+)+:?$} &&				    check_absolute_file($1, $herecurr)) {					#				} else {					check_absolute_file($file, $herecurr);				}			}		} # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php		if (($realfile =~ /^$/ || $line =~ /^\+/) &&		    $rawline !~ m/^$UTF8*$/) {			my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/); 			my $blank = copy_spacing($rawline);			my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";			my $hereptr = "$hereline$ptr\n"; 			CHK("INVALID_UTF8",			    "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);		} # Check if it's the start of a commit log# (not a header line and we haven't seen the patch filename)		if ($in_header_lines && $realfile =~ /^$/ &&		    $rawline !~ /^(commit\b|from\b|[\w-]+:).+$/i) {			$in_header_lines = 0;			$in_commit_log = 1;		} # Still not yet in a patch, check for any UTF-8		if ($in_commit_log && $realfile =~ /^$/ &&		    $rawline =~ /$NON_ASCII_UTF8/) {			CHK("UTF8_BEFORE_PATCH",			    "8-bit UTF-8 used in possible commit log\n" . $herecurr);		} # ignore non-hunk lines and lines being removed		next if (!$hunk_line || $line =~ /^-/); #trailing whitespace		if ($line =~ /^\+.*\015/) {			my $herevet = "$here\n" . cat_vet($rawline) . "\n";			ERROR("DOS_LINE_ENDINGS",			      "DOS line endings\n" . $herevet); 		} elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {			my $herevet = "$here\n" . cat_vet($rawline) . "\n";			ERROR("TRAILING_WHITESPACE",			      "trailing whitespace\n" . $herevet);			$rpt_cleaners = 1;		} # check for Kconfig help text having a real description# Only applies when adding the entry originally, after that we do not have# sufficient context to determine whether it is indeed long enough.		if ($realfile =~ /Kconfig/ &&		    $line =~ /.\s*config\s+/) {			my $length = 0;			my $cnt = $realcnt;			my $ln = $linenr + 1;			my $f;			my $is_start = 0;			my $is_end = 0;			for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {				$f = $lines[$ln - 1];				$cnt-- if ($lines[$ln - 1] !~ /^-/);				$is_end = $lines[$ln - 1] =~ /^\+/; 				next if ($f =~ /^-/); 				if ($lines[$ln - 1] =~ /.\s*(?:bool|tristate)\s*\"/) {					$is_start = 1;				} elsif ($lines[$ln - 1] =~ /.\s*(?:---)?help(?:---)?$/) {					$length = -1;				} 				$f =~ s/^.//;				$f =~ s/#.*//;				$f =~ s/^\s+//;				next if ($f =~ /^$/);				if ($f =~ /^\s*config\s/) {					$is_end = 1;					last;				}				$length++;			}			WARN("CONFIG_DESCRIPTION",			     "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_start && $is_end && $length < 4);			#print "is_start<$is_start> is_end<$is_end> length<$length>\n";		} 		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&		    ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {			my $flag = $1;			my $replacement = {				'EXTRA_AFLAGS' =>   'asflags-y',				'EXTRA_CFLAGS' =>   'ccflags-y',				'EXTRA_CPPFLAGS' => 'cppflags-y',				'EXTRA_LDFLAGS' =>  'ldflags-y',			}; 			WARN("DEPRECATED_VARIABLE",			     "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});		} # check we are in a valid source file if not then ignore this hunk		next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); #80 column limit		if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&		    $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&		    !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||		    $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&		    $length > 80)		{			WARN("LONG_LINE",			     "line over 80 characters\n" . $herecurr);		} # Check for user-visible strings broken across lines, which breaks the ability# to grep for the string.  Limited to strings used as parameters (those# following an open parenthesis), which almost completely eliminates false# positives, as well as warning only once per parameter rather than once per# line of the string.  Make an exception when the previous string ends in a# newline (multiple lines in one string constant) or \n\t (common in inline# assembly to indent the instruction on the following line).		if ($line =~ /^\+\s*"/ &&		    $prevline =~ /"\s*$/ &&		    $prevline =~ /\(/ &&		    $prevrawline !~ /\\n(?:\\t)*"\s*$/) {			WARN("SPLIT_STRING",			     "quoted string split across lines\n" . $hereprev);		} # check for spaces before a quoted newline		if ($rawline =~ /^.*\".*\s\\n/) {			WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",			     "unnecessary whitespace before a quoted newline\n" . $herecurr);		} # check for adding lines without a newline.		if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {			WARN("MISSING_EOF_NEWLINE",			     "adding a line without newline at end of file\n" . $herecurr);		} # Blackfin: use hi/lo macros		if ($realfile =~ m@arch/blackfin/.*\.S$@) {			if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {				my $herevet = "$here\n" . cat_vet($line) . "\n";				ERROR("LO_MACRO",				      "use the LO() macro, not (... & 0xFFFF)\n" . $herevet);			}			if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {				my $herevet = "$here\n" . cat_vet($line) . "\n";				ERROR("HI_MACRO",				      "use the HI() macro, not (... >> 16)\n" . $herevet);			}		} # check we are in a valid source file C or perl if not then ignore this hunk		next if ($realfile !~ /\.(h|c|pl)$/); # at the beginning of a line any tabs must come first and anything# more than 8 must use tabs.		if ($rawline =~ /^\+\s* \t\s*\S/ ||		    $rawline =~ /^\+\s*        \s*/) {			my $herevet = "$here\n" . cat_vet($rawline) . "\n";			ERROR("CODE_INDENT",			      "code indent should use tabs where possible\n" . $herevet);			$rpt_cleaners = 1;		} # check for space before tabs.		if ($rawline =~ /^\+/ && $rawline =~ / \t/) {			my $herevet = "$here\n" . cat_vet($rawline) . "\n";			WARN("SPACE_BEFORE_TAB",			     "please, no space before tabs\n" . $herevet);		} # check for && or || at the start of a line		if ($rawline =~ /^\+\s*(&&|\|\|)/) {			CHK("LOGICAL_CONTINUATIONS",			    "Logical continuations should be on the previous line\n" . $hereprev);		} # check multi-line statement indentation matches previous line		if ($^V && $^V ge 5.10.0 &&		    $prevline =~ /^\+(\t*)(if \(|$Ident\().*(\&\&|\|\||,)\s*$/) {			$prevline =~ /^\+(\t*)(.*)$/;			my $oldindent = $1;			my $rest = $2; 			my $pos = pos_last_openparen($rest);			if ($pos >= 0) {				$line =~ /^\+([ \t]*)/;				my $newindent = $1; 				my $goodtabindent = $oldindent .					"\t" x ($pos / 8) .					" "  x ($pos % 8);				my $goodspaceindent = $oldindent . " "  x $pos; 				if ($newindent ne $goodtabindent &&				    $newindent ne $goodspaceindent) {					CHK("PARENTHESIS_ALIGNMENT",					    "Alignment should match open parenthesis\n" . $hereprev);				}			}		} 		if ($line =~ /^\+.*\*[ \t]*\)[ \t]+/) {			CHK("SPACING",			    "No space is necessary after a cast\n" . $hereprev);		} # check for spaces at the beginning of a line.# Exceptions:#  1) within comments#  2) indented preprocessor commands#  3) hanging labels		if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/)  {			my $herevet = "$here\n" . cat_vet($rawline) . "\n";			WARN("LEADING_SPACE",			     "please, no spaces at the start of a line\n" . $herevet);		} # check we are in a valid C source file if not then ignore this hunk		next if ($realfile !~ /\.(h|c)$/); # check for RCS/CVS revision markers		if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {			WARN("CVS_KEYWORD",			     "CVS style keyword markers, these will _not_ be updated\n". $herecurr);		} # Blackfin: don't use __builtin_bfin_[cs]sync		if ($line =~ /__builtin_bfin_csync/) {			my $herevet = "$here\n" . cat_vet($line) . "\n";			ERROR("CSYNC",			      "use the CSYNC() macro in asm/blackfin.h\n" . $herevet);		}		if ($line =~ /__builtin_bfin_ssync/) {			my $herevet = "$here\n" . cat_vet($line) . "\n";			ERROR("SSYNC",			      "use the SSYNC() macro in asm/blackfin.h\n" . $herevet);		} # Check for potential 'bare' types		my ($stat, $cond, $line_nr_next, $remain_next, $off_next,		    $realline_next);#print "LINE<$line>\n";		if ($linenr >= $suppress_statement &&		    $realcnt && $line =~ /.\s*\S/) {			($stat, $cond, $line_nr_next, $remain_next, $off_next) =				ctx_statement_block($linenr, $realcnt, 0);			$stat =~ s/\n./\n /g;			$cond =~ s/\n./\n /g; #print "linenr<$linenr> <$stat>\n";			# If this statement has no statement boundaries within			# it there is no point in retrying a statement scan			# until we hit end of it.			my $frag = $stat; $frag =~ s/;+\s*$//;			if ($frag !~ /(?:{|;)/) {#print "skip<$line_nr_next>\n";				$suppress_statement = $line_nr_next;			} 			# Find the real next line.			$realline_next = $line_nr_next;			if (defined $realline_next &&			    (!defined $lines[$realline_next - 1] ||			     substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {				$realline_next++;			} 			my $s = $stat;			$s =~ s/{.*$//s; 			# Ignore goto labels.			if ($s =~ /$Ident:\*$/s) { 			# Ignore functions being called			} elsif ($s =~ /^.\s*$Ident\s*\(/s) { 			} elsif ($s =~ /^.\s*else\b/s) { 			# declarations always start with types			} elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {				my $type = $1;				$type =~ s/\s+/ /g;				possible($type, "A:" . $s); 			# definitions in global scope can only start with types			} elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {				possible($1, "B:" . $s);			} 			# any (foo ... *) is a pointer cast, and foo is a type			while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {				possible($1, "C:" . $s);			} 			# Check for any sort of function declaration.			# int foo(something bar, other baz);			# void (*store_gdt)(x86_descr_ptr *);			if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {				my ($name_len) = length($1); 				my $ctx = $s;				substr($ctx, 0, $name_len + 1, '');				$ctx =~ s/\)[^\)]*$//; 				for my $arg (split(/\s*,\s*/, $ctx)) {					if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) { 						possible($1, "D:" . $s);					}				}			} 		} ## Checks which may be anchored in the context.# # Check for switch () and associated case and default# statements should be at the same indent.		if ($line=~/\bswitch\s*\(.*\)/) {			my $err = '';			my $sep = '';			my @ctx = ctx_block_outer($linenr, $realcnt);			shift(@ctx);			for my $ctx (@ctx) {				my ($clen, $cindent) = line_stats($ctx);				if ($ctx =~ /^\+\s*(case\s+|default:)/ &&							$indent != $cindent) {					$err .= "$sep$ctx\n";					$sep = '';				} else {					$sep = "[...]\n";				}			}

Lines 1501–2000 of 3566. Previous lines