]> git.proxmox.com Git - mirror_qemu.git/blobdiff - scripts/checkpatch.pl
error: Consistently name Error * objects err, and not errp
[mirror_qemu.git] / scripts / checkpatch.pl
index 4ac00a912157b17a23430a304ba48147395802ca..efca817b9be15324f5d0e0eefc7b9eb9eb9b9ff7 100755 (executable)
@@ -582,7 +582,7 @@ sub statement_block_size {
        my ($stmt) = @_;
 
        $stmt =~ s/(^|\n)./$1/g;
-       $stmt =~ s/^\s*{//;
+       $stmt =~ s/^\s*\{//;
        $stmt =~ s/}\s*$//;
        $stmt =~ s/^\s*//;
        $stmt =~ s/\s*$//;
@@ -1010,7 +1010,9 @@ sub possible {
                        case|
                        else|
                        asm|__asm__|
-                       do
+                       do|
+                       \#|
+                       \#\#
                )(?:\s|$)|
                ^(?:typedef|struct|enum)\b
            )}x;
@@ -1479,7 +1481,7 @@ sub process {
                        # 79 or 80 characters, it is no longer possible to add a space and an
                        # opening brace there)
                        if ($#ctx == 0 && $ctx !~ /{\s*/ &&
-                           defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/ &&
+                           defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*\{/ &&
                            defined($lines[$ctx_ln - 2]) && length($lines[$ctx_ln - 2]) < 80) {
                                ERROR("that open brace { should be on the previous line\n" .
                                        "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
@@ -1519,7 +1521,7 @@ sub process {
                        my $continuation = 0;
                        my $check = 0;
                        $s =~ s/^.*\bdo\b//;
-                       $s =~ s/^\s*{//;
+                       $s =~ s/^\s*\{//;
                        if ($s =~ s/^\s*\\//) {
                                $continuation = 1;
                        }
@@ -1618,7 +1620,7 @@ sub process {
                }
 
 # check for initialisation to aggregates open brace on the next line
-               if ($line =~ /^.\s*{/ &&
+               if ($line =~ /^.\s*\{/ &&
                    $prevline =~ /(?:^|[^=])=\s*$/) {
                        ERROR("that open brace { should be on the previous line\n" . $hereprev);
                }
@@ -1693,22 +1695,17 @@ sub process {
 
 # function brace can't be on same line, except for #defines of do while,
 # or if closed on same line
-               if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
-                   !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
+               if (($line=~/$Type\s*$Ident\(.*\).*\s\{/) and
+                   !($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) {
                        ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
                }
 
 # open braces for enum, union and struct go on the same line.
-               if ($line =~ /^.\s*{/ &&
+               if ($line =~ /^.\s*\{/ &&
                    $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
                        ERROR("open brace '{' following $1 go on the same line\n" . $hereprev);
                }
 
-# ... however, open braces on typedef lines should be avoided.
-               if ($line =~ /^.\s*typedef\s+(enum|union|struct)(?:\s+$Ident\b)?.*[^;]$/) {
-                       ERROR("typedefs should be separate from struct declaration\n" . $herecurr);
-               }
-
 # missing space after union, struct or enum definition
                if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
                    ERROR("missing space after $1 definition\n" . $herecurr);
@@ -1853,7 +1850,7 @@ sub process {
                                 # not required when having a single },{ on one line
                                } elsif ($op eq ',') {
                                        if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/ &&
-                                            ($elements[$n] . $elements[$n + 2]) !~ " *}{") {
+                                            ($elements[$n] . $elements[$n + 2]) !~ " *}\\{") {
                                                ERROR("space required after that '$op' $at\n" . $hereptr);
                                        }
 
@@ -1893,19 +1890,6 @@ sub process {
                                                ERROR("space prohibited after that '$op' $at\n" . $hereptr);
                                        }
 
-
-                               # << and >> may either have or not have spaces both sides
-                               } elsif ($op eq '<<' or $op eq '>>' or
-                                        $op eq '&' or $op eq '^' or $op eq '|' or
-                                        $op eq '+' or $op eq '-' or
-                                        $op eq '*' or $op eq '/' or
-                                        $op eq '%')
-                               {
-                                       if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
-                                               ERROR("need consistent spacing around '$op' $at\n" .
-                                                       $hereptr);
-                                       }
-
                                # A colon needs no spaces before when it is
                                # terminating a case value or a label.
                                } elsif ($opv eq ':C' || $opv eq ':L') {
@@ -1953,8 +1937,8 @@ sub process {
                }
 
 #need space before brace following if, while, etc
-               if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
-                   $line =~ /do{/) {
+               if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) ||
+                   $line =~ /do\{/) {
                        ERROR("space required before the open brace '{'\n" . $herecurr);
                }
 
@@ -2268,7 +2252,7 @@ sub process {
                                        my $spaced_block = $block;
                                        $spaced_block =~ s/\n\+/ /g;
 
-                                       $seen++ if ($spaced_block =~ /^\s*{/);
+                                       $seen++ if ($spaced_block =~ /^\s*\{/);
 
                                         print "APW: cond<$cond> block<$block> allowed<$allowed>\n"
                                             if $dbg_adv_apw;
@@ -2463,8 +2447,8 @@ sub process {
                        WARN("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
                }
 
-# recommend qemu_strto* over strto*
-               if ($line =~ /\b(strto.*?)\s*\(/) {
+# recommend qemu_strto* over strto* for numeric conversions
+               if ($line =~ /\b(strto[^k].*?)\s*\(/) {
                        WARN("consider using qemu_$1 in preference to $1\n" . $herecurr);
                }
 # check for module_init(), use category-specific init macros explicitly please