[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC][PATCH v1 2/2] Adjust checkpatch.pl to xen CODING_STYLE



Signed-off-by: Don Slutz <dslutz@xxxxxxxxxxx>
---
 scripts/checkpatch.pl | 82 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 51 insertions(+), 31 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 053e432..1034f25 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -97,9 +97,13 @@ my $dbg_values = 0;
 my $dbg_possible = 0;
 my $dbg_type = 0;
 my $dbg_attr = 0;
+my $dbg_adv_ero = 0;
+my $dbg_adv_obn = 0;
 my $dbg_adv_dcs = 0;
 my $dbg_adv_checking = 0;
 my $dbg_adv_apw = 0;
+my $dbg_adv_cond = 0;
+my $dbg_adv_space = 0;
 for my $key (keys %debug) {
        ## no critic
        eval "\${dbg_$key} = '$debug{$key}';";
@@ -206,13 +210,9 @@ our $UTF8  = qr {
        |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
 }x;
 
-# There are still some false positives, but this catches most
-# common cases.
 our $typeTypedefs = qr{(?x:
-        [A-Z][A-Z\d_]*[a-z][A-Za-z\d_]*     # camelcase
-        | [A-Z][A-Z\d_]*AIOCB               # all uppercase
-        | [A-Z][A-Z\d_]*CPU                 # all uppercase
-        | QEMUBH                            # all uppercase
+       (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
+       atomic_t
 )};
 
 our $logFunctions = qr{(?x:
@@ -336,8 +336,8 @@ sub top_of_kernel_tree {
 
        my @tree_check = (
                "COPYING", "MAINTAINERS", "Makefile",
-               "README", "docs", "VERSION",
-               "vl.c"
+               "README", "docs", "xen", "tools",
+               "CODING_STYLE"
        );
 
        foreach my $check (@tree_check) {
@@ -1094,6 +1094,8 @@ sub possible {
 my $prefix = '';
 
 sub report {
+        print "ERO: $_[0]"
+           if $dbg_adv_ero;
        if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) {
                return 0;
        }
@@ -1636,11 +1638,13 @@ sub process {
                                $ctx_ln++;
                        }
 
-                       #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
-                       #print 
"pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
+                       if ($dbg_adv_obn) {
+                           print "OBN: realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
+                           print "OBN: 
pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
+                       }
 
-                       if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && 
$lines[$ctx_ln - 1] =~ /^\+\s*{/) {
-                               ERROR("that open brace { should be on the 
previous line\n" .
+                       if ($ctx =~ /{\s*/ && $ctx !~ /do\s+{/ && 
defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] !~ /^\+\s*{/) {
+                               ERROR("that open brace { should be on the next 
line\n" .
                                        "$here\n$ctx\n$rawlines[$ctx_ln - 
1]\n");
                        }
                        if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
@@ -2226,13 +2230,28 @@ sub process {
 
 # check spacing on parentheses
                if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
-                   $line !~ /for\s*\(\s+;/) {
+                    $line !~ /\s\)\s\?\s/ &&
+                   $line !~ /for\s*\(\s+;/ && $line !~ 
/\b(if|while|for|switch)\s\(\s\S/) {
+                       print "SPACE: prevline<$prevline> line<$line>\n"
+                           if $dbg_adv_space;
                        ERROR("space prohibited after that open parenthesis 
'('\n" . $herecurr);
                }
                if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
-                   $line !~ /for\s*\(.*;\s+\)/ &&
+                    $line !~ /\s\)\s\?\s/ &&
+                   $line !~ /for\s*\(.*;\s+\)/ && $line !~ 
/\b(if|while|for|switch)\s\(\s\S/ &&
+                   $prevline !~ /\b(if|while|for|switch)\s\(\s\S/ &&
                    $line !~ /:\s+\)/) {
-                       ERROR("space prohibited before that close parenthesis 
')'\n" . $herecurr);
+                        my $both_line = $prevline.$line;
+                        my @opens = split(/\(/, $both_line, -1);
+                        my $open_cnt = $#opens;
+                        my @closes = split(/\)/, $both_line, -1);
+                        my $close_cnt = $#closes;
+                       if ($dbg_adv_space) {
+                           print "SPACE: prevline<$prevline> line<$line>\n";
+                            print "SPACE: open_cnt<$open_cnt> 
close_cnt<$close_cnt>\n";
+                       }
+                       ERROR("space prohibited before that close parenthesis 
')'\n" . $herecurr)
+                           if $open_cnt == $close_cnt;
                }
 
 # Return is not a function.
@@ -2361,10 +2380,10 @@ sub process {
 
                # Check for }<nl>else {, these must be at the same
                # indent level to be relevant to each other.
-               if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
-                                               $previndent == $indent) {
-                       ERROR("else should follow close brace '}'\n" . 
$hereprev);
-               }
+#              if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
+#                                              $previndent == $indent) {
+#                      ERROR("else should follow close brace '}'\n" . 
$hereprev);
+#              }
 
                if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
                                                $previndent == $indent) {
@@ -2511,8 +2530,8 @@ sub process {
                        WARN("vmlinux.lds.h needs VMLINUX_SYMBOL() around 
C-visible symbols\n" . $herecurr);
                }
 
-# check for missing bracing round if etc
-               if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
+# check for redundant bracing round if etc
+               if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
                        my ($level, $endln, @chunks) =
                                ctx_statement_full($linenr, $realcnt, 1);
                         if ($dbg_adv_apw) {
@@ -2520,7 +2539,7 @@ sub process {
                             print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"
                                 if $#chunks >= 1;
                         }
-                       if ($#chunks >= 0 && $level == 0) {
+                       if ($#chunks > 0 && $level == 0) {
                                my $allowed = 0;
                                my $seen = 0;
                                my $herectx = $here . "\n";
@@ -2532,7 +2551,8 @@ sub process {
                                        my ($whitespace) = ($cond =~ 
/^((?:\s*\n[+-])*\s*)/s);
                                        my $offset = 
statement_rawlines($whitespace) - 1;
 
-                                       #print "COND<$cond> 
whitespace<$whitespace> offset<$offset>\n";
+                                       print "COND<$cond> 
whitespace<$whitespace> offset<$offset>\n"
+                                           if $dbg_adv_cond;
 
                                        # We have looked at and allowed this 
specific line.
                                        $suppress_ifbraces{$ln + $offset} = 1;
@@ -2544,10 +2564,10 @@ sub process {
 
                                        $seen++ if ($block =~ /^\s*{/);
 
-                                        print "APW: cond<$cond> block<$block> 
allowed<$allowed>\n"
+                                        print "APW: cond<$cond> block<$block> 
allowed<$allowed> seen<$seen>\n"
                                             if $dbg_adv_apw;
                                        if (statement_lines($cond) > 1) {
-                                            print "APW: ALLOWED: cond<$cond>\n"
+                                            print "APW: ALLOWED: lines > 1 
cond<$cond>\n"
                                                 if $dbg_adv_apw;
                                             $allowed = 1;
                                        }
@@ -2557,13 +2577,13 @@ sub process {
                                             $allowed = 1;
                                        }
                                        if (statement_block_size($block) > 1) {
-                                            print "APW: ALLOWED: lines 
block<$block>\n"
+                                            print "APW: ALLOWED: block_size > 
1 block<$block>\n"
                                                 if $dbg_adv_apw;
                                             $allowed = 1;
                                        }
                                }
-                               if ($seen != ($#chunks + 1)) {
-                                       WARN("braces {} are necessary for all 
arms of this statement\n" . $herectx);
+                               if ($seen && !$allowed) {
+                                   WARN("braces {} are not necessary for any 
arm of this statement\n" . $herectx);
                                }
                        }
                }
@@ -2595,7 +2615,7 @@ sub process {
                                substr($block, 0, length($cond), '');
                        }
                        if (statement_lines($cond) > 1) {
-                            print "APW: ALLOWED: cond<$cond>\n"
+                            print "APW: ALLOWED: lines cond<$cond>\n"
                                 if $dbg_adv_apw;
                             $allowed = 1;
                        }
@@ -2623,7 +2643,7 @@ sub process {
                        }
                         print "DCS: level=$level block<$block> 
allowed=$allowed\n"
                             if $dbg_adv_dcs;
-                       if ($level == 0 && $block !~ /^\s*\{/ && !$allowed) {
+                       if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
                                my $herectx = $here . "\n";;
                                my $cnt = statement_rawlines($block);
 
@@ -2631,7 +2651,7 @@ sub process {
                                        $herectx .= raw_line($linenr, $n) . 
"\n";;
                                }
 
-                               WARN("braces {} are necessary even for single 
statement blocks\n" . $herectx);
+                               WARN("braces {} are not necessary for single 
statement blocks\n" . $herectx);
                        }
                }
 
-- 
1.8.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.