6972 lines · 205.6 KB · Perl
RawDownload
)}; our @typeListMisordered = (	qr{char\s+(?:un)?signed},	qr{int\s+(?:(?:un)?signed\s+)?short\s},	qr{int\s+short(?:\s+(?:un)?signed)},	qr{short\s+int(?:\s+(?:un)?signed)},	qr{(?:un)?signed\s+int\s+short},	qr{short\s+(?:un)?signed},	qr{long\s+int\s+(?:un)?signed},	qr{int\s+long\s+(?:un)?signed},	qr{long\s+(?:un)?signed\s+int},	qr{int\s+(?:un)?signed\s+long},	qr{int\s+(?:un)?signed},	qr{int\s+long\s+long\s+(?:un)?signed},	qr{long\s+long\s+int\s+(?:un)?signed},	qr{long\s+long\s+(?:un)?signed\s+int},	qr{long\s+long\s+(?:un)?signed},	qr{long\s+(?:un)?signed},); our @typeList = (	qr{void},	qr{(?:(?:un)?signed\s+)?char},	qr{(?:(?:un)?signed\s+)?short\s+int},	qr{(?:(?:un)?signed\s+)?short},	qr{(?:(?:un)?signed\s+)?int},	qr{(?:(?:un)?signed\s+)?long\s+int},	qr{(?:(?:un)?signed\s+)?long\s+long\s+int},	qr{(?:(?:un)?signed\s+)?long\s+long},	qr{(?:(?:un)?signed\s+)?long},	qr{(?:un)?signed},	qr{float},	qr{double},	qr{bool},	qr{struct\s+$Ident},	qr{union\s+$Ident},	qr{enum\s+$Ident},	qr{${Ident}_t},	qr{${Ident}_handler},	qr{${Ident}_handler_fn},	@typeListMisordered,); our $C90_int_types = qr{(?x:	long\s+long\s+int\s+(?:un)?signed|	long\s+long\s+(?:un)?signed\s+int|	long\s+long\s+(?:un)?signed|	(?:(?:un)?signed\s+)?long\s+long\s+int|	(?:(?:un)?signed\s+)?long\s+long|	int\s+long\s+long\s+(?:un)?signed|	int\s+(?:(?:un)?signed\s+)?long\s+long| 	long\s+int\s+(?:un)?signed|	long\s+(?:un)?signed\s+int|	long\s+(?:un)?signed|	(?:(?:un)?signed\s+)?long\s+int|	(?:(?:un)?signed\s+)?long|	int\s+long\s+(?:un)?signed|	int\s+(?:(?:un)?signed\s+)?long| 	int\s+(?:un)?signed|	(?:(?:un)?signed\s+)?int)}; our @typeListFile = ();our @typeListWithAttr = (	@typeList,	qr{struct\s+$InitAttribute\s+$Ident},	qr{union\s+$InitAttribute\s+$Ident},); our @modifierList = (	qr{fastcall},);our @modifierListFile = (); our @mode_permission_funcs = (	["module_param", 3],	["module_param_(?:array|named|string)", 4],	["module_param_array_named", 5],	["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2],	["proc_create(?:_data|)", 2],	["(?:CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2],	["IIO_DEV_ATTR_[A-Z_]+", 1],	["SENSOR_(?:DEVICE_|)ATTR_2", 2],	["SENSOR_TEMPLATE(?:_2|)", 3],	["__ATTR", 2],); my $word_pattern = '\b[A-Z]?[a-z]{2,}\b'; #Create a search pattern for all these functions to speed up a loop belowour $mode_perms_search = "";foreach my $entry (@mode_permission_funcs) {	$mode_perms_search .= '|' if ($mode_perms_search ne "");	$mode_perms_search .= $entry->[0];}$mode_perms_search = "(?:${mode_perms_search})"; our %deprecated_apis = (	"synchronize_rcu_bh"			=> "synchronize_rcu",	"synchronize_rcu_bh_expedited"		=> "synchronize_rcu_expedited",	"call_rcu_bh"				=> "call_rcu",	"rcu_barrier_bh"			=> "rcu_barrier",	"synchronize_sched"			=> "synchronize_rcu",	"synchronize_sched_expedited"		=> "synchronize_rcu_expedited",	"call_rcu_sched"			=> "call_rcu",	"rcu_barrier_sched"			=> "rcu_barrier",	"get_state_synchronize_sched"		=> "get_state_synchronize_rcu",	"cond_synchronize_sched"		=> "cond_synchronize_rcu",); #Create a search pattern for all these strings to speed up a loop belowour $deprecated_apis_search = "";foreach my $entry (keys %deprecated_apis) {	$deprecated_apis_search .= '|' if ($deprecated_apis_search ne "");	$deprecated_apis_search .= $entry;}$deprecated_apis_search = "(?:${deprecated_apis_search})"; our $mode_perms_world_writable = qr{	S_IWUGO		|	S_IWOTH		|	S_IRWXUGO	|	S_IALLUGO	|	0[0-7][0-7][2367]}x; our %mode_permission_string_types = (	"S_IRWXU" => 0700,	"S_IRUSR" => 0400,	"S_IWUSR" => 0200,	"S_IXUSR" => 0100,	"S_IRWXG" => 0070,	"S_IRGRP" => 0040,	"S_IWGRP" => 0020,	"S_IXGRP" => 0010,	"S_IRWXO" => 0007,	"S_IROTH" => 0004,	"S_IWOTH" => 0002,	"S_IXOTH" => 0001,	"S_IRWXUGO" => 0777,	"S_IRUGO" => 0444,	"S_IWUGO" => 0222,	"S_IXUGO" => 0111,); #Create a search pattern for all these strings to speed up a loop belowour $mode_perms_string_search = "";foreach my $entry (keys %mode_permission_string_types) {	$mode_perms_string_search .= '|' if ($mode_perms_string_search ne "");	$mode_perms_string_search .= $entry;}our $single_mode_perms_string_search = "(?:${mode_perms_string_search})";our $multi_mode_perms_string_search = qr{	${single_mode_perms_string_search}	(?:\s*\|\s*${single_mode_perms_string_search})*}x; sub perms_to_octal {	my ($string) = @_; 	return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/); 	my $val = "";	my $oval = "";	my $to = 0;	my $curpos = 0;	my $lastpos = 0;	while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) {		$curpos = pos($string);		my $match = $2;		my $omatch = $1;		last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));		$lastpos = $curpos;		$to |= $mode_permission_string_types{$match};		$val .= '\s*\|\s*' if ($val ne "");		$val .= $match;		$oval .= $omatch;	}	$oval =~ s/^\s*\|\s*//;	$oval =~ s/\s*\|\s*$//;	return sprintf("%04o", $to);} our $allowed_asm_includes = qr{(?x:	irq|	memory|	time|	reboot)};# memory.h: ARM has a custom one # Load common spelling mistakes and build regular expression list.my $misspellings;my %spelling_fix; if (open(my $spelling, '<', $spelling_file)) {	while (<$spelling>) {		my $line = $_; 		$line =~ s/\s*\n?$//g;		$line =~ s/^\s*//g; 		next if ($line =~ m/^\s*#/);		next if ($line =~ m/^\s*$/); 		my ($suspect, $fix) = split(/\|\|/, $line); 		$spelling_fix{$suspect} = $fix;	}	close($spelling);} else {	warn "No typos will be found - file '$spelling_file': $!\n";} if ($codespell) {	if (open(my $spelling, '<', $codespellfile)) {		while (<$spelling>) {			my $line = $_; 			$line =~ s/\s*\n?$//g;			$line =~ s/^\s*//g; 			next if ($line =~ m/^\s*#/);			next if ($line =~ m/^\s*$/);			next if ($line =~ m/, disabled/i); 			$line =~ s/,.*$//; 			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*\()}; 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("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git")); 	my $root_path = abs_path($root);	my $status = `cd "$root_path"; echo "$license" | python 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 ".git") {		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 ".git") {		$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_commit_info {	my ($commit, $id, $desc) = @_; 	return ($id, $desc) if ((which("git") eq "") || !(-e ".git")); 	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\./) {		$id = undef;	} else {		$id = substr($lines[0], 0, 12);		$desc = substr($lines[0], 41);	} 

Lines 501–1000 of 6972. Previous lines