Skip to content
Snippets Groups Projects
checkpatch.pl 82.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • 				stacktrace_ops|
    				sysfs_ops|
    				tty_operations|
    				usb_mon_operations|
    				wd_ops}x;
    
    		if ($line !~ /\bconst\b/ &&
    
    		    $line =~ /\bstruct\s+($struct_ops)\b/) {
    
    			WARN("struct $1 should normally be const\n" .
    				$herecurr);
    
    
    # use of NR_CPUS is usually wrong
    # ignore definitions of NR_CPUS and usage to define arrays as likely right
    		if ($line =~ /\bNR_CPUS\b/ &&
    
    		    $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
    		    $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
    
    		    $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
    		    $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
    		    $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
    
    		{
    			WARN("usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
    		}
    
    
    # check for %L{u,d,i} in strings
    		my $string;
    		while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
    			$string = substr($rawline, $-[1], $+[1] - $-[1]);
    
    			$string =~ s/%%/__/g;
    
    			if ($string =~ /(?<!%)%L[udi]/) {
    				WARN("\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
    				last;
    			}
    		}
    
    
    # whine mightly about in_atomic
    		if ($line =~ /\bin_atomic\s*\(/) {
    			if ($realfile =~ m@^drivers/@) {
    				ERROR("do not use in_atomic in drivers\n" . $herecurr);
    
    			} elsif ($realfile !~ m@^kernel/@) {
    
    				WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
    			}
    		}
    
    
    # check for lockdep_set_novalidate_class
    		if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
    		    $line =~ /__lockdep_no_validate__\s*\)/ ) {
    			if ($realfile !~ m@^kernel/lockdep@ &&
    			    $realfile !~ m@^include/linux/lockdep@ &&
    			    $realfile !~ m@^drivers/base/core@) {
    				ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
    			}
    		}
    
    
    		if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
    		    $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
    			WARN("Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
    		}
    
    
    		# Check for memset with swapped arguments
    		if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
    			ERROR("memset size is 3rd argument, not the second.\n" . $herecurr);
    		}
    
    	}
    
    	# If we have no input at all, then there is nothing to report on
    	# so just keep quiet.
    	if ($#rawlines == -1) {
    		exit(0);
    
    	# In mailback mode only produce a report in the negative, for
    	# things that appear to be patches.
    	if ($mailback && ($clean == 1 || !$is_patch)) {
    		exit(0);
    	}
    
    	# This is not a patch, and we are are in 'no-patch' mode so
    	# just keep quiet.
    	if (!$chk_patch && !$is_patch) {
    		exit(0);
    	}
    
    	if (!$is_patch) {
    
    		ERROR("Does not appear to be a unified-diff format patch\n");
    
    	}
    	if ($is_patch && $chk_signoff && $signoff == 0) {
    
    		ERROR("Missing Signed-off-by: line(s)\n");
    
    	print report_dump();
    
    	if ($summary && !($clean == 1 && $quiet == 1)) {
    		print "$filename " if ($summary_file);
    
    		print "total: $cnt_error errors, $cnt_warn warnings, " .
    			(($check)? "$cnt_chk checks, " : "") .
    			"$cnt_lines lines checked\n";
    		print "\n" if ($quiet == 0);
    
    	if ($quiet == 0) {
    		# If there were whitespace errors which cleanpatch can fix
    		# then suggest that.
    		if ($rpt_cleaners) {
    			print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
    			print "      scripts/cleanfile\n\n";
    
    	if ($clean == 1 && $quiet == 0) {
    
    		print "$vname has no obvious style problems and is ready for submission.\n"
    
    	}
    	if ($clean == 0 && $quiet == 0) {
    
    		print "$vname has style problems, please review.  If any of these errors\n";
    
    		print "are false positives report them to the maintainer, see\n";
    		print "CHECKPATCH in MAINTAINERS.\n";
    	}
    
    	return $clean;
    }