]> Git Repo - qemu.git/blobdiff - scripts/checkpatch.pl
trace: add trace_mem_build_info_no_se_be/le
[qemu.git] / scripts / checkpatch.pl
index 1b4b812e28fa16ac684a845779dcea5e02512749..e3d8c2cdfc82a3f39d2be0f345eb9940b2a7647c 100755 (executable)
@@ -224,9 +224,8 @@ our $NonptrType;
 our $Type;
 our $Declare;
 
-our $UTF8      = qr {
-       [\x09\x0A\x0D\x20-\x7E]              # ASCII
-       | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
+our $NON_ASCII_UTF8    = qr{
+       [\xC2-\xDF][\x80-\xBF]               # non-overlong 2-byte
        |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
        | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
        |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
@@ -235,6 +234,11 @@ our $UTF8  = qr {
        |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
 }x;
 
+our $UTF8      = qr{
+       [\x09\x0A\x0D\x20-\x7E]              # ASCII
+       | $NON_ASCII_UTF8
+}x;
+
 # There are still some false positives, but this catches most
 # common cases.
 our $typeTypedefs = qr{(?x:
@@ -265,7 +269,36 @@ our @typeList = (
        qr{${Ident}_handler_fn},
        qr{target_(?:u)?long},
        qr{hwaddr},
+        # external libraries
        qr{xml${Ident}},
+       qr{xen\w+_handle},
+       # Glib definitions
+       qr{gchar},
+       qr{gshort},
+       qr{glong},
+       qr{gint},
+       qr{gboolean},
+       qr{guchar},
+       qr{gushort},
+       qr{gulong},
+       qr{guint},
+       qr{gfloat},
+       qr{gdouble},
+       qr{gpointer},
+       qr{gconstpointer},
+       qr{gint8},
+       qr{guint8},
+       qr{gint16},
+       qr{guint16},
+       qr{gint32},
+       qr{guint32},
+       qr{gint64},
+       qr{guint64},
+       qr{gsize},
+       qr{gssize},
+       qr{goffset},
+       qr{gintptr},
+       qr{guintptr},
 );
 
 # This can be modified by sub possible.  Since it can be empty, be careful
@@ -1178,6 +1211,11 @@ sub process {
        my $signoff = 0;
        my $is_patch = 0;
 
+       my $in_header_lines = $file ? 0 : 1;
+       my $in_commit_log = 0;          #Scanning lines before patch
+       my $reported_maintainer_file = 0;
+       my $non_utf8_charset = 0;
+
        our @report = ();
        our $cnt_lines = 0;
        our $cnt_error = 0;
@@ -1330,7 +1368,6 @@ sub process {
                if ($line =~ /^diff --git.*?(\S+)$/) {
                        $realfile = $1;
                        $realfile =~ s@^([^/]*)/@@;
-
                } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
                        $realfile = $1;
                        $realfile =~ s@^([^/]*)/@@;
@@ -1369,6 +1406,8 @@ sub process {
                if ($line =~ /^\s*signed-off-by:/i) {
                        # This is a signoff, if ugly, so do not double report.
                        $signoff++;
+                       $in_commit_log = 0;
+
                        if (!($line =~ /^\s*Signed-off-by:/)) {
                                ERROR("The correct form is \"Signed-off-by\"\n" .
                                        $herecurr);
@@ -1379,6 +1418,22 @@ sub process {
                        }
                }
 
+# Check if MAINTAINERS is being updated.  If so, there's probably no need to
+# emit the "does MAINTAINERS need updating?" message on file add/move/delete
+               if ($line =~ /^\s*MAINTAINERS\s*\|/) {
+                       $reported_maintainer_file = 1;
+               }
+
+# Check for added, moved or deleted files
+               if (!$reported_maintainer_file && !$in_commit_log &&
+                   ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
+                    $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
+                    ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
+                     (defined($1) || defined($2))))) {
+                       $reported_maintainer_file = 1;
+                       WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
+               }
+
 # Check for wrappage within a valid hunk of the file
                if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
                        ERROR("patch seems to be corrupt (line wrapped?)\n" .
@@ -1397,6 +1452,28 @@ sub process {
                        ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
                }
 
+# Check if it's the start of a commit log
+# (not a header line and we haven't seen the patch filename)
+               if ($in_header_lines && $realfile =~ /^$/ &&
+                   !($rawline =~ /^\s+\S/ ||
+                     $rawline =~ /^(commit\b|from\b|[\w-]+:).*$/i)) {
+                       $in_header_lines = 0;
+                       $in_commit_log = 1;
+               }
+
+# Check if there is UTF-8 in a commit log when a mail header has explicitly
+# declined it, i.e defined some charset where it is missing.
+               if ($in_header_lines &&
+                   $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
+                   $1 !~ /utf-8/i) {
+                       $non_utf8_charset = 1;
+               }
+
+               if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
+                   $rawline =~ /$NON_ASCII_UTF8/) {
+                       WARN("8-bit UTF-8 used in possible commit log\n" . $herecurr);
+               }
+
 # ignore non-hunk lines and lines being removed
                next if (!$hunk_line || $line =~ /^-/);
 
@@ -1447,9 +1524,10 @@ sub process {
 # check we are in a valid source file if not then ignore this hunk
                next if ($realfile !~ /$SrcFile/);
 
-#90 column limit
+#90 column limit; exempt URLs, if no other words on line
                if ($line =~ /^\+/ &&
                    !($line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
+                   !($rawline =~ /^[^[:alnum:]]*https?:\S*$/) &&
                    $length > 80)
                {
                        if ($length > 90) {
@@ -2352,8 +2430,21 @@ sub process {
                        }
                }
 
-# check for missing bracing round if etc
-               if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
+# check for missing bracing around if etc
+               if ($line =~ /(^.*)\b(?:if|while|for)\b/ &&
+                       $line !~ /\#\s*if/) {
+                       my $allowed = 0;
+
+                       # Check the pre-context.
+                       if ($line =~ /(\}.*?)$/) {
+                               my $pre = $1;
+
+                               if ($line !~ /else/) {
+                                       print "APW: ALLOWED: pre<$pre> line<$line>\n"
+                                               if $dbg_adv_apw;
+                                       $allowed = 1;
+                               }
+                       }
                        my ($level, $endln, @chunks) =
                                ctx_statement_full($linenr, $realcnt, 1);
                         if ($dbg_adv_apw) {
@@ -2362,7 +2453,6 @@ sub process {
                                 if $#chunks >= 1;
                         }
                        if ($#chunks >= 0 && $level == 0) {
-                               my $allowed = 0;
                                my $seen = 0;
                                my $herectx = $here . "\n";
                                my $ln = $linenr - 1;
@@ -2406,7 +2496,7 @@ sub process {
                                             $allowed = 1;
                                        }
                                }
-                               if ($seen != ($#chunks + 1)) {
+                               if ($seen != ($#chunks + 1) && !$allowed) {
                                        ERROR("braces {} are necessary for all arms of this statement\n" . $herectx);
                                }
                        }
@@ -2584,6 +2674,11 @@ sub process {
                        ERROR("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
                }
 
+# recommend g_path_get_* over g_strdup(basename/dirname(...))
+               if ($line =~ /\bg_strdup\s*\(\s*(basename|dirname)\s*\(/) {
+                       WARN("consider using g_path_get_$1() in preference to g_strdup($1())\n" . $herecurr);
+               }
+
 # recommend qemu_strto* over strto* for numeric conversions
                if ($line =~ /\b(strto[^kd].*?)\s*\(/) {
                        ERROR("consider using qemu_$1 in preference to $1\n" . $herecurr);
This page took 0.031077 seconds and 4 git commands to generate.