7976 lines · 239.6 KB · Perl
RawDownload
 			my ($suspect, $fix) = split(/->/, $line); 			$spelling_fix{$suspect} = $fix;		}		close($spelling);	} else {		warn "No codespell typos will be found - file '$codespellfile': $!\n";	}} $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; sub read_words {	my ($wordsRef, $file) = @_; 	if (open(my $words, '<', $file)) {		while (<$words>) {			my $line = $_; 			$line =~ s/\s*\n?$//g;			$line =~ s/^\s*//g; 			next if ($line =~ m/^\s*#/);			next if ($line =~ m/^\s*$/);			if ($line =~ /\s/) {				print("$file: '$line' invalid - ignored\n");				next;			} 			$$wordsRef .= '|' if (defined $$wordsRef);			$$wordsRef .= $line;		}		close($file);		return 1;	} 	return 0;} my $const_structs;if (show_type("CONST_STRUCT")) {	read_words(\$const_structs, $conststructsfile)	    or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";} if (defined($typedefsfile)) {	my $typeOtherTypedefs;	read_words(\$typeOtherTypedefs, $typedefsfile)	    or warn "No additional types will be considered - file '$typedefsfile': $!\n";	$typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs);} sub build_types {	my $mods = "(?x:  \n" . join("|\n  ", (@modifierList, @modifierListFile)) . "\n)";	my $all = "(?x:  \n" . join("|\n  ", (@typeList, @typeListFile)) . "\n)";	my $Misordered = "(?x:  \n" . join("|\n  ", @typeListMisordered) . "\n)";	my $allWithAttr = "(?x:  \n" . join("|\n  ", @typeListWithAttr) . "\n)";	$Modifier	= qr{(?:$Attribute|$Sparse|$mods)};	$BasicType	= qr{				(?:$typeTypedefs\b)|				(?:${all}\b)		}x;	$NonptrType	= qr{			(?:$Modifier\s+|const\s+)*			(?:				(?:typeof|__typeof__)\s*\([^\)]*\)|				(?:$typeTypedefs\b)|				(?:${all}\b)			)			(?:\s+$Modifier|\s+const)*		  }x;	$NonptrTypeMisordered	= qr{			(?:$Modifier\s+|const\s+)*			(?:				(?:${Misordered}\b)			)			(?:\s+$Modifier|\s+const)*		  }x;	$NonptrTypeWithAttr	= qr{			(?:$Modifier\s+|const\s+)*			(?:				(?:typeof|__typeof__)\s*\([^\)]*\)|				(?:$typeTypedefs\b)|				(?:${allWithAttr}\b)			)			(?:\s+$Modifier|\s+const)*		  }x;	$Type	= qr{			$NonptrType			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}			(?:\s+$Inline|\s+$Modifier)*		  }x;	$TypeMisordered	= qr{			$NonptrTypeMisordered			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}			(?:\s+$Inline|\s+$Modifier)*		  }x;	$Declare	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};	$DeclareMisordered	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};}build_types(); our $Typecast	= qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; # Using $balanced_parens, $LvalOrFunc, or $FuncArg# requires at least perl version v5.10.0# Any use must be runtime checked with $^V our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;our $LvalOrFunc	= qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)}; our $declaration_macros = qr{(?x:	(?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|	(?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|	(?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(|	(?:$Storage\s+)?(?:XA_STATE|XA_STATE_ORDER)\s*\(|	__cacheline_group_(?:begin|end)(?:_aligned)?\s*\(|	__dma_from_device_group_(?:begin|end)\s*\()}; our %allow_repeated_words = (	add => '',	added => '',	bad => '',	be => '',); sub deparenthesize {	my ($string) = @_;	return "" if (!defined($string)); 	while ($string =~ /^\s*\(.*\)\s*$/) {		$string =~ s@^\s*\(\s*@@;		$string =~ s@\s*\)\s*$@@;	} 	$string =~ s@\s+@ @g; 	return $string;} sub seed_camelcase_file {	my ($file) = @_; 	return if (!(-f $file)); 	local $/; 	open(my $include_file, '<', "$file")	    or warn "$P: Can't read '$file' $!\n";	my $text = <$include_file>;	close($include_file); 	my @lines = split('\n', $text); 	foreach my $line (@lines) {		next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);		if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {			$camelcase{$1} = 1;		} elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {			$camelcase{$1} = 1;		} elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {			$camelcase{$1} = 1;		}	}} our %maintained_status = (); sub is_maintained_obsolete {	my ($filename) = @_; 	return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl")); 	if (!exists($maintained_status{$filename})) {		$maintained_status{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`;	} 	return $maintained_status{$filename} =~ /obsolete/i;} sub is_SPDX_License_valid {	my ($license) = @_; 	return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot")); 	my $root_path = abs_path($root);	my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;	return 0 if ($status ne "");	return 1;} my $camelcase_seeded = 0;sub seed_camelcase_includes {	return if ($camelcase_seeded); 	my $files;	my $camelcase_cache = "";	my @include_files = (); 	$camelcase_seeded = 1; 	if (-e "$gitroot") {		my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`;		chomp $git_last_include_commit;		$camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";	} else {		my $last_mod_date = 0;		$files = `find $root/include -name "*.h"`;		@include_files = split('\n', $files);		foreach my $file (@include_files) {			my $date = POSIX::strftime("%Y%m%d%H%M",						   localtime((stat $file)[9]));			$last_mod_date = $date if ($last_mod_date < $date);		}		$camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";	} 	if ($camelcase_cache ne "" && -f $camelcase_cache) {		open(my $camelcase_file, '<', "$camelcase_cache")		    or warn "$P: Can't read '$camelcase_cache' $!\n";		while (<$camelcase_file>) {			chomp;			$camelcase{$_} = 1;		}		close($camelcase_file); 		return;	} 	if (-e "$gitroot") {		$files = `${git_command} ls-files "include/*.h"`;		@include_files = split('\n', $files);	} 	foreach my $file (@include_files) {		seed_camelcase_file($file);	} 	if ($camelcase_cache ne "") {		unlink glob ".checkpatch-camelcase.*";		open(my $camelcase_file, '>', "$camelcase_cache")		    or warn "$P: Can't write '$camelcase_cache' $!\n";		foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {			print $camelcase_file ("$_\n");		}		close($camelcase_file);	}} sub git_is_single_file {	my ($filename) = @_; 	return 0 if ((which("git") eq "") || !(-e "$gitroot")); 	my $output = `${git_command} ls-files -- $filename 2>/dev/null`;	my $count = $output =~ tr/\n//;	return $count eq 1 && $output =~ m{^${filename}$};} sub git_commit_info {	my ($commit, $id, $desc) = @_; 	return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot")); 	my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;	$output =~ s/^\s*//gm;	my @lines = split("\n", $output); 	return ($id, $desc) if ($#lines < 0); 	if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous/) {# Maybe one day convert this block of bash into something that returns# all matching commit ids, but it's very slow...##		echo "checking commits $1..."#		git rev-list --remotes | grep -i "^$1" |#		while read line ; do#		    git log --format='%H %s' -1 $line |#		    echo "commit $(cut -c 1-12,41-)"#		done	} elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./ ||		 $lines[0] =~ /^fatal: bad object $commit/) {		$id = undef;	} else {		$id = substr($lines[0], 0, 12);		$desc = substr($lines[0], 41);	} 	return ($id, $desc);} $chk_signoff = 0 if ($file);$chk_fixes_tag = 0 if ($file); my @rawlines = ();my @lines = ();my @fixed = ();my @fixed_inserted = ();my @fixed_deleted = ();my $fixlinenr = -1; # If input is git commits, extract all commits from the commit expressions.# For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.die "$P: No git repository found\n" if ($git && !-e "$gitroot"); if ($git) {	my @commits = ();	foreach my $commit_expr (@ARGV) {		my $git_range;		if ($commit_expr =~ m/^(.*)-(\d+)$/) {			$git_range = "-$2 $1";		} elsif ($commit_expr =~ m/\.\./) {			$git_range = "$commit_expr";		} else {			$git_range = "-1 $commit_expr";		}		my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;		foreach my $line (split(/\n/, $lines)) {			$line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;			next if (!defined($1) || !defined($2));			my $sha1 = $1;			my $subject = $2;			unshift(@commits, $sha1);			$git_commits{$sha1} = $subject;		}	}	die "$P: no git commits after extraction!\n" if (@commits == 0);	@ARGV = @commits;} my $vname;$allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"};for my $filename (@ARGV) {	my $FILE;	my $is_git_file = git_is_single_file($filename);	my $oldfile = $file;	$file = 1 if ($is_git_file);	if ($git) {		open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||			die "$P: $filename: git format-patch failed - $!\n";	} elsif ($file) {		open($FILE, '-|', "diff -u /dev/null $filename") ||			die "$P: $filename: diff failed - $!\n";	} elsif ($filename eq '-') {		open($FILE, '<&STDIN');	} else {		open($FILE, '<', "$filename") ||			die "$P: $filename: open failed - $!\n";	}	if ($filename eq '-') {		$vname = 'Your patch';	} elsif ($git) {		$vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")';	} else {		$vname = $filename;	}	while (<$FILE>) {		chomp;		push(@rawlines, $_);		$vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);	}	close($FILE); 	if ($#ARGV > 0 && $quiet == 0) {		print '-' x length($vname) . "\n";		print "$vname\n";		print '-' x length($vname) . "\n";	} 	if (!process($filename)) {		$exit = 1;	}	@rawlines = ();	@lines = ();	@fixed = ();	@fixed_inserted = ();	@fixed_deleted = ();	$fixlinenr = -1;	@modifierListFile = ();	@typeListFile = ();	build_types();	$file = $oldfile if ($is_git_file);} if (!$quiet) {	hash_show_words(\%use_type, "Used");	hash_show_words(\%ignore_type, "Ignored"); 	if (!$perl_version_ok) {		print << "EOM" NOTE: perl $^V is not modern enough to detect all possible issues.      An upgrade to at least perl $minimum_perl_version is suggested.EOM	}	if ($exit) {		print << "EOM" NOTE: If any of the errors are false positives, please report      them to the maintainer, see CHECKPATCH in MAINTAINERS.EOM	}} exit($exit); sub top_of_kernel_tree {	my ($root) = @_; 	my @tree_check = (		"COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",		"README", "Documentation", "arch", "include", "drivers",		"fs", "init", "ipc", "kernel", "lib", "scripts",	); 	foreach my $check (@tree_check) {		if (! -e $root . '/' . $check) {			return 0;		}	}	return 1;} sub parse_email {	my ($formatted_email) = @_; 	my $name = "";	my $quoted = "";	my $name_comment = "";	my $address = "";	my $comment = ""; 	if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {		$name = $1;		$address = $2;		$comment = $3 if defined $3;	} elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {		$address = $1;		$comment = $2 if defined $2;	} elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {		$address = $1;		$comment = $2 if defined $2;		$formatted_email =~ s/\Q$address\E.*$//;		$name = $formatted_email;		$name = trim($name);		$name =~ s/^\"|\"$//g;		# If there's a name left after stripping spaces and		# leading quotes, and the address doesn't have both		# leading and trailing angle brackets, the address		# is invalid. ie:		#   "joe smith joe@smith.com" bad		#   "joe smith <joe@smith.com" bad		if ($name ne "" && $address !~ /^<[^>]+>$/) {			$name = "";			$address = "";			$comment = "";		}	} 	# Extract comments from names excluding quoted parts	# "John D. (Doe)" - Do not extract	if ($name =~ s/\"(.+)\"//) {		$quoted = $1;	}	while ($name =~ s/\s*($balanced_parens)\s*/ /) {		$name_comment .= trim($1);	}	$name =~ s/^[ \"]+|[ \"]+$//g;	$name = trim("$quoted $name"); 	$address = trim($address);	$address =~ s/^\<|\>$//g;	$comment = trim($comment); 	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes		$name = "\"$name\"";	} 	return ($name, $name_comment, $address, $comment);} sub format_email {	my ($name, $name_comment, $address, $comment) = @_; 	my $formatted_email; 	$name =~ s/^[ \"]+|[ \"]+$//g;	$address = trim($address);	$address =~ s/(?:\.|\,|\")+$//; ##trailing commas, dots or quotes 	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes		$name = "\"$name\"";	} 	$name_comment = trim($name_comment);

Lines 1001–1500 of 7976. Previous lines