summaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl60
1 files changed, 50 insertions, 10 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 62669700d629..34f1415ae964 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2517,16 +2517,56 @@ sub process {
2517# check we are in a valid source file if not then ignore this hunk 2517# check we are in a valid source file if not then ignore this hunk
2518 next if ($realfile !~ /\.(h|c|s|S|pl|sh|dtsi|dts)$/); 2518 next if ($realfile !~ /\.(h|c|s|S|pl|sh|dtsi|dts)$/);
2519 2519
2520#line length limit 2520# line length limit (with some exclusions)
2521 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 2521#
2522 $rawline !~ /^.\s*\*\s*\@$Ident\s/ && 2522# There are a few types of lines that may extend beyond $max_line_length:
2523 !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?$String\s*(?:|,|\)\s*;)\s*$/ || 2523# logging functions like pr_info that end in a string
2524 $line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ || 2524# lines with a single string
2525 $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) && 2525# #defines that are a single string
2526 $length > $max_line_length) 2526#
2527 { 2527# There are 3 different line length message types:
2528 WARN("LONG_LINE", 2528# LONG_LINE_COMMENT a comment starts before but extends beyond $max_linelength
2529 "line over $max_line_length characters\n" . $herecurr); 2529# LONG_LINE_STRING a string starts before but extends beyond $max_line_length
2530# LONG_LINE all other lines longer than $max_line_length
2531#
2532# if LONG_LINE is ignored, the other 2 types are also ignored
2533#
2534
2535 if ($length > $max_line_length) {
2536 my $msg_type = "LONG_LINE";
2537
2538 # Check the allowed long line types first
2539
2540 # logging functions that end in a string that starts
2541 # before $max_line_length
2542 if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
2543 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
2544 $msg_type = "";
2545
2546 # lines with only strings (w/ possible termination)
2547 # #defines with only strings
2548 } elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
2549 $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
2550 $msg_type = "";
2551
2552 # Otherwise set the alternate message types
2553
2554 # a comment starts before $max_line_length
2555 } elsif ($line =~ /($;[\s$;]*)$/ &&
2556 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
2557 $msg_type = "LONG_LINE_COMMENT"
2558
2559 # a quoted string starts before $max_line_length
2560 } elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
2561 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
2562 $msg_type = "LONG_LINE_STRING"
2563 }
2564
2565 if ($msg_type ne "" &&
2566 (show_type("LONG_LINE") || show_type($msg_type))) {
2567 WARN($msg_type,
2568 "line over $max_line_length characters\n" . $herecurr);
2569 }
2530 } 2570 }
2531 2571
2532# check for adding lines without a newline. 2572# check for adding lines without a newline.