7976 lines · 239.6 KB · Perl
RawDownload
				ERROR("EXECUTE_PERMISSIONS",				      "do not set execute permissions for source files\n" . $permhere);			}		} # Check the patch for a From:		if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {			$author = $1;			my $curline = $linenr;			while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) {				$author .= $1;			}			$author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);			$author =~ s/"//g;			$author = reformat_email($author);		} # Check the patch for a signoff:		if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {			$signoff++;			$in_commit_log = 0;			if ($author ne ''  && $authorsignoff != 1) {				if (same_email_addresses($1, $author)) {					$authorsignoff = 1;				} else {					my $ctx = $1;					my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);					my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author); 					if (lc $email_address eq lc $author_address && $email_name eq $author_name) {						$author_sob = $ctx;						$authorsignoff = 2;					} elsif (lc $email_address eq lc $author_address) {						$author_sob = $ctx;						$authorsignoff = 3;					} elsif ($email_name eq $author_name) {						$author_sob = $ctx;						$authorsignoff = 4; 						my $address1 = $email_address;						my $address2 = $author_address; 						if ($address1 =~ /(\S+)\+\S+(\@.*)/) {							$address1 = "$1$2";						}						if ($address2 =~ /(\S+)\+\S+(\@.*)/) {							$address2 = "$1$2";						}						if ($address1 eq $address2) {							$authorsignoff = 5;						}					}				}			}		} # Check for invalid patch separator		if ($in_commit_log &&		    $line =~ /^---.+/) {			if (ERROR("BAD_COMMIT_SEPARATOR",				  "Invalid commit separator - some tools may have problems applying this\n" . $herecurr) &&			    $fix) {				$fixed[$fixlinenr] =~ s/-/=/g;			}		} # Check for patch separator		if ($line =~ /^---$/) {			$has_patch_separator = 1;			$in_commit_log = 0;		} # Check if MAINTAINERS is being updated.  If so, there's probably no need to# emit the "does MAINTAINERS need updating?" message on file add/move/delete		if ($line =~ /^\s*MAINTAINERS\s*\|/) {			$reported_maintainer_file = 1;		} # Check signature styles		if (!$in_header_lines &&		    $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {			my $space_before = $1;			my $sign_off = $2;			my $space_after = $3;			my $email = $4;			my $ucfirst_sign_off = ucfirst(lc($sign_off)); 			if ($sign_off !~ /$signature_tags/) {				my $suggested_signature = find_standard_signature($sign_off);				if ($suggested_signature eq "") {					WARN("BAD_SIGN_OFF",					     "Non-standard signature: $sign_off\n" . $herecurr);				} else {					if (WARN("BAD_SIGN_OFF",						 "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) &&					    $fix) {						$fixed[$fixlinenr] =~ s/$sign_off/$suggested_signature/;					}				}			}			if (defined $space_before && $space_before ne "") {				if (WARN("BAD_SIGN_OFF",					 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&				    $fix) {					$fixed[$fixlinenr] =					    "$ucfirst_sign_off $email";				}			}			if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {				if (WARN("BAD_SIGN_OFF",					 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&				    $fix) {					$fixed[$fixlinenr] =					    "$ucfirst_sign_off $email";				} 			}			if (!defined $space_after || $space_after ne " ") {				if (WARN("BAD_SIGN_OFF",					 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&				    $fix) {					$fixed[$fixlinenr] =					    "$ucfirst_sign_off $email";				}			} 			# Assisted-by uses AGENT_NAME:MODEL_VERSION format, not email			if ($sign_off =~ /^Assisted-by:/i) {				if ($email !~ /^\S+:\S+/) {					WARN("BAD_SIGN_OFF",					     "Assisted-by expects 'AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]' format\n" . $herecurr);				}				next;			} 			my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);			my $suggested_email = format_email(($email_name, $name_comment, $email_address, $comment));			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 (!same_email_addresses($email, $suggested_email)) {					if (WARN("BAD_SIGN_OFF",						 "email address '$email' might be better as '$suggested_email'\n" . $herecurr) &&					    $fix) {						$fixed[$fixlinenr] =~ s/\Q$email\E/$suggested_email/;					}				} 				# Address part shouldn't have comments				my $stripped_address = $email_address;				$stripped_address =~ s/\([^\(\)]*\)//g;				if ($email_address ne $stripped_address) {					if (WARN("BAD_SIGN_OFF",						 "address part of email should not have comments: '$email_address'\n" . $herecurr) &&					    $fix) {						$fixed[$fixlinenr] =~ s/\Q$email_address\E/$stripped_address/;					}				} 				# Only one name comment should be allowed				my $comment_count = () = $name_comment =~ /\([^\)]+\)/g;				if ($comment_count > 1) {					WARN("BAD_SIGN_OFF",					     "Use a single name comment in email: '$email'\n" . $herecurr);				}  				# stable@vger.kernel.org or stable@kernel.org shouldn't				# have an email name. In addition comments should strictly				# begin with a #				if ($email =~ /^.*stable\@(?:vger\.)?kernel\.org/i) {					if (($comment ne "" && $comment !~ /^#.+/) ||					    ($email_name ne "")) {						my $cur_name = $email_name;						my $new_comment = $comment;						$cur_name =~ s/[a-zA-Z\s\-\"]+//g; 						# Remove brackets enclosing comment text						# and # from start of comments to get comment text						$new_comment =~ s/^\((.*)\)$/$1/;						$new_comment =~ s/^\[(.*)\]$/$1/;						$new_comment =~ s/^[\s\#]+|\s+$//g; 						$new_comment = trim("$new_comment $cur_name") if ($cur_name ne $new_comment);						$new_comment = " # $new_comment" if ($new_comment ne "");						my $new_email = "$email_address$new_comment"; 						if (WARN("BAD_STABLE_ADDRESS_STYLE",							 "Invalid email format for stable: '$email', prefer '$new_email'\n" . $herecurr) &&						    $fix) {							$fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;						}					}				} elsif ($comment ne "" && $comment !~ /^(?:#.+|\(.+\))$/) {					my $new_comment = $comment; 					# Extract comment text from within brackets or					# c89 style /*...*/ comments					$new_comment =~ s/^\[(.*)\]$/$1/;					$new_comment =~ s/^\/\*(.*)\*\/$/$1/; 					$new_comment = trim($new_comment);					$new_comment =~ s/^[^\w]$//; # Single lettered comment with non word character is usually a typo					$new_comment = "($new_comment)" if ($new_comment ne "");					my $new_email = format_email($email_name, $name_comment, $email_address, $new_comment); 					if (WARN("BAD_SIGN_OFF",						 "Unexpected content after email: '$email', should be: '$new_email'\n" . $herecurr) &&					    $fix) {						$fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;					}				}			} # Check for duplicate signatures			my $sig_nospace = $line;			$sig_nospace =~ s/\s//g;			$sig_nospace = lc($sig_nospace);			if (defined $signatures{$sig_nospace}) {				WARN("BAD_SIGN_OFF",				     "Duplicate signature\n" . $herecurr);			} else {				$signatures{$sig_nospace} = 1;			} # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email			if ($sign_off =~ /^co-developed-by:$/i) {				if ($email eq $author) {					WARN("BAD_SIGN_OFF",					      "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . $herecurr);				}				if (!defined $lines[$linenr]) {					WARN("BAD_SIGN_OFF",					     "Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr);				} elsif ($rawlines[$linenr] !~ /^signed-off-by:\s*(.*)/i) {					WARN("BAD_SIGN_OFF",					     "Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr . $rawlines[$linenr] . "\n");				} elsif ($1 ne $email) {					WARN("BAD_SIGN_OFF",					     "Co-developed-by and Signed-off-by: name/email do not match\n" . $herecurr . $rawlines[$linenr] . "\n");				}			} # check if Reported-by: is followed by a Closes: tag			if ($sign_off =~ /^reported(?:|-and-tested)-by:$/i) {				if (!defined $lines[$linenr]) {					WARN("BAD_REPORTED_BY_LINK",					     "Reported-by: should be immediately followed by Closes: or Link: with a URL to the report\n" . $herecurr . "\n");				} elsif ($rawlines[$linenr] !~ /^(closes|link):\s*/i) {					WARN("BAD_REPORTED_BY_LINK",					     "Reported-by: should be immediately followed by Closes: or Link: with a URL to the report\n" . $herecurr . $rawlines[$linenr] . "\n");				}			}		} # These indicate a bug fix		if (!$in_header_lines && !$is_patch &&			$line =~ /^This reverts commit/) {			$is_revert = 1;		} 		if (!$in_header_lines && !$is_patch &&		    $line =~ /((?:(?:BUG: K.|UB)SAN: |Call Trace:|stable\@|syzkaller))/) {			$needs_fixes_tag = $1;		} # Check Fixes: styles is correct		if (!$in_header_lines &&		    $line =~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})(?:\s*($balanced_parens))?/i) {			my $tag = $1;			my $orig_commit = $2;			my $title;			my $title_has_quotes = 0;			$fixes_tag = 1;			if (defined $3) {				# Always strip leading/trailing parens then double quotes if existing				$title = substr($3, 1, -1);				if ($title =~ /^".*"$/) {					$title = substr($title, 1, -1);					$title_has_quotes = 1;				}			} else {				$title = "commit title"			}  			my $tag_case = not ($tag eq "Fixes:");			my $tag_space = not ($line =~ /^fixes:? [0-9a-f]{5,40} ($balanced_parens)/i); 			my $id_length = not ($orig_commit =~ /^[0-9a-f]{12,40}$/i);			my $id_case = not ($orig_commit !~ /[A-F]/); 			my $id = "0123456789ab";			my ($cid, $ctitle) = git_commit_info($orig_commit, $id,							     $title); 			if (defined($cid) && ($ctitle ne $title || $tag_case || $tag_space || $id_length || $id_case || !$title_has_quotes)) {				my $fixed = "Fixes: $cid (\"$ctitle\")";				if (WARN("BAD_FIXES_TAG",				     "Please use correct Fixes: style 'Fixes: <12+ chars of sha1> (\"<title line>\")' - ie: '$fixed'\n" . $herecurr) &&				    $fix) {					$fixed[$fixlinenr] = $fixed;				}			}		} # Check email subject for common tools that don't need to be mentioned		if ($in_header_lines &&		    $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {			WARN("EMAIL_SUBJECT",			     "A patch subject line should describe the change not the tool that found it\n" . $herecurr);		} # Check for Gerrit Change-Ids not in any patch context		if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {			if (ERROR("GERRIT_CHANGE_ID",			          "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&			    $fix) {				fix_delete_line($fixlinenr, $rawline);			}		} # Check if the commit log is in a possible stack dump		if ($in_commit_log && !$commit_log_possible_stack_dump &&		    ($line =~ /^\s*(?:WARNING:|BUG:)/ ||		     $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||					# timestamp		     $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||		     $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||		     $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {					# stack dump address styles			$commit_log_possible_stack_dump = 1;		} # Check for line lengths > 75 in commit log, warn once		if ($in_commit_log && !$commit_log_long_line &&		    length($line) > 75 &&		    !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||					# file delta changes		      $line =~ /^\s*(?:[\w\.\-\+]*\/)++[\w\.\-\+]+:/ ||					# filename then :		      $line =~ /^\s*(?:Fixes:|https?:|$link_tags_search|$signature_tags)/i ||					# A Fixes:, link or signature tag line		      $commit_log_possible_stack_dump)) {			WARN("COMMIT_LOG_LONG_LINE",			     "Prefer a maximum 75 chars per line (possible unwrapped commit description?)\n" . $herecurr);			$commit_log_long_line = 1;		} # Reset possible stack dump if a blank line is found		if ($in_commit_log && $commit_log_possible_stack_dump &&		    $line =~ /^\s*$/) {			$commit_log_possible_stack_dump = 0;		} # Check for odd tags before a URI/URL		if ($in_commit_log &&		    $line =~ /^\s*(\w+:)\s*http/ && $1 !~ /^$link_tags_search$/) {			if ($1 =~ /^v(?:ersion)?\d+/i) {				WARN("COMMIT_LOG_VERSIONING",				     "Patch version information should be after the --- line\n" . $herecurr);			} else {				WARN("COMMIT_LOG_USE_LINK",				     "Unknown link reference '$1', use $link_tags_print instead\n" . $herecurr);			}		} # Check for misuse of the link tags		if ($in_commit_log &&		    $line =~ /^\s*(\w+:)\s*(\S+)/) {			my $tag = $1;			my $value = $2;			if ($tag =~ /^$link_tags_search$/ && $value !~ m{^https?://}) {				WARN("COMMIT_LOG_WRONG_LINK",				     "'$tag' should be followed by a public http(s) link\n" . $herecurr);			}		} # Check for lines starting with a #		if ($in_commit_log && $line =~ /^#/) {			if (WARN("COMMIT_COMMENT_SYMBOL",				 "Commit log lines starting with '#' are dropped by git as comments\n" . $herecurr) &&			    $fix) {				$fixed[$fixlinenr] =~ s/^/ /;			}		} # Check for auto-generated unhandled placeholder text (mostly for cover letters)		if (($in_commit_log || $in_header_lines) &&		    $rawline =~ /(?:SUBJECT|BLURB) HERE/) {			ERROR("PLACEHOLDER_USE",			      "Placeholder text detected\n" . $herecurr);		} # Check for git id commit length and improperly formed commit descriptions# A correctly formed commit description is:#    commit <SHA-1 hash length 12+ chars> ("Complete commit subject")# with the commit subject '("' prefix and '")' suffix# This is a fairly compilicated block as it tests for what appears to be# bare SHA-1 hash with  minimum length of 5.  It also avoids several types of# possible SHA-1 matches.# A commit match can span multiple lines so this block attempts to find a# complete typical commit on a maximum of 3 lines		if ($perl_version_ok &&		    $in_commit_log && !$commit_log_possible_stack_dump &&		    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&		    $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&		    (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||		      ($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||		     ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&		      $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&		      $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {			my $init_char = "c";			my $orig_commit = "";			my $short = 1;			my $long = 0;			my $case = 1;			my $space = 1;			my $id = '0123456789ab';			my $orig_desc = "commit description";			my $description = "";			my $herectx = $herecurr;			my $has_parens = 0;			my $has_quotes = 0; 			my $input = $line;			if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {				for (my $n = 0; $n < 2; $n++) {					if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {						$orig_desc = $1;						$has_parens = 1;						# Always strip leading/trailing parens then double quotes if existing						$orig_desc = substr($orig_desc, 1, -1);						if ($orig_desc =~ /^".*"$/) {							$orig_desc = substr($orig_desc, 1, -1);							$has_quotes = 1;						}						last;					}					last if ($#lines < $linenr + $n);					$input .= " " . trim($rawlines[$linenr + $n]);					$herectx .= "$rawlines[$linenr + $n]\n";				}				$herectx = $herecurr if (!$has_parens);			} 			if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {				$init_char = $1;				$orig_commit = lc($2);				$short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);				$long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);				$space = 0 if ($input =~ /\bcommit [0-9a-f]/i);				$case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);			} elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {				$orig_commit = lc($1);			} 			($id, $description) = git_commit_info($orig_commit,							      $id, $orig_desc); 			if (defined($id) &&			    ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) &&			    $last_git_commit_id_linenr != $linenr - 1) {				ERROR("GIT_COMMIT_ID",				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);			}			#don't report the next line if this line ends in commit and the sha1 hash is the next line			$last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);		} # Check for mailing list archives other than lore.kernel.org		if ($rawline =~ m{http.*\b$obsolete_archives}) {			WARN("PREFER_LORE_ARCHIVE",			     "Use lore.kernel.org archive links when possible - see https://lore.kernel.org/lists.html\n" . $herecurr);		} # Check for added, moved or deleted files		if (!$reported_maintainer_file && !$in_commit_log &&		    ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||		     $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||		     ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&		      (defined($1) || defined($2))))) {			$is_patch = 1;			$reported_maintainer_file = 1;			WARN("FILE_PATH_CHANGES",			     "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);		} # Check for adding new DT bindings not in schema format		if (!$in_commit_log &&		    ($line =~ /^new file mode\s*\d+\s*$/) &&		    ($realfile =~ m@^Documentation/devicetree/bindings/.*\.txt$@)) {			WARN("DT_SCHEMA_BINDING_PATCH",			     "DT bindings should be in DT schema format. See: Documentation/devicetree/bindings/writing-schema.rst\n");

Lines 3001–3500 of 7976. Previous lines