提交 c2df8783 编写于 作者: P Paolo Bonzini

checkpatch: bump most warnings to errors

This only leaves a warning-level message for the extra-long lines
soft limit.  Everything else is bumped up.

In the future warnings can be added for checks that can have false
positives.
Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 8fbe3d1f
...@@ -1289,11 +1289,11 @@ sub process { ...@@ -1289,11 +1289,11 @@ sub process {
# This is a signoff, if ugly, so do not double report. # This is a signoff, if ugly, so do not double report.
$signoff++; $signoff++;
if (!($line =~ /^\s*Signed-off-by:/)) { if (!($line =~ /^\s*Signed-off-by:/)) {
WARN("Signed-off-by: is the preferred form\n" . ERROR("The correct form is \"Signed-off-by\"\n" .
$herecurr); $herecurr);
} }
if ($line =~ /^\s*signed-off-by:\S/i) { if ($line =~ /^\s*signed-off-by:\S/i) {
WARN("space required after Signed-off-by:\n" . ERROR("space required after Signed-off-by:\n" .
$herecurr); $herecurr);
} }
} }
...@@ -1350,17 +1350,17 @@ sub process { ...@@ -1350,17 +1350,17 @@ sub process {
# check for spaces before a quoted newline # check for spaces before a quoted newline
if ($rawline =~ /^.*\".*\s\\n/) { if ($rawline =~ /^.*\".*\s\\n/) {
WARN("unnecessary whitespace before a quoted newline\n" . $herecurr); ERROR("unnecessary whitespace before a quoted newline\n" . $herecurr);
} }
# check for adding lines without a newline. # check for adding lines without a newline.
if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
WARN("adding a line without newline at end of file\n" . $herecurr); ERROR("adding a line without newline at end of file\n" . $herecurr);
} }
# check for RCS/CVS revision markers # check for RCS/CVS revision markers
if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|\b)/) { if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|\b)/) {
WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); ERROR("CVS style keyword markers, these will _not_ be updated\n". $herecurr);
} }
# tabs are only allowed in assembly source code, and in # tabs are only allowed in assembly source code, and in
...@@ -1506,7 +1506,7 @@ sub process { ...@@ -1506,7 +1506,7 @@ sub process {
{ {
my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
if ($nindent > $indent) { if ($nindent > $indent) {
WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . ERROR("trailing semicolon indicates no statements, indent implies otherwise\n" .
"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
} }
} }
...@@ -1594,7 +1594,7 @@ sub process { ...@@ -1594,7 +1594,7 @@ sub process {
if ($check && (($sindent % 4) != 0 || if ($check && (($sindent % 4) != 0 ||
($sindent <= $indent && $s ne ''))) { ($sindent <= $indent && $s ne ''))) {
WARN("suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); ERROR("suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
} }
} }
...@@ -1772,7 +1772,7 @@ sub process { ...@@ -1772,7 +1772,7 @@ sub process {
} elsif ($ctx =~ /$Type$/) { } elsif ($ctx =~ /$Type$/) {
} else { } else {
WARN("space prohibited between function name and open parenthesis '('\n" . $herecurr); ERROR("space prohibited between function name and open parenthesis '('\n" . $herecurr);
} }
} }
# Check operator spacing. # Check operator spacing.
...@@ -2011,7 +2011,7 @@ sub process { ...@@ -2011,7 +2011,7 @@ sub process {
if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
my $name = $1; my $name = $1;
if ($name ne 'EOF' && $name ne 'ERROR') { if ($name ne 'EOF' && $name ne 'ERROR') {
WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr); ERROR("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
} }
} }
...@@ -2083,7 +2083,7 @@ sub process { ...@@ -2083,7 +2083,7 @@ sub process {
(?:\&\&|\|\||\)|\]) (?:\&\&|\|\||\)|\])
)/x) )/x)
{ {
WARN("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr); ERROR("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
} }
# if and else should not have general statements after it # if and else should not have general statements after it
...@@ -2139,7 +2139,7 @@ sub process { ...@@ -2139,7 +2139,7 @@ sub process {
#no spaces allowed after \ in define #no spaces allowed after \ in define
if ($line=~/\#\s*define.*\\\s$/) { if ($line=~/\#\s*define.*\\\s$/) {
WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); ERROR("Whitespace after \\ makes next lines useless\n" . $herecurr);
} }
# multi-statement macros should be enclosed in a do while loop, grab the # multi-statement macros should be enclosed in a do while loop, grab the
...@@ -2291,7 +2291,7 @@ sub process { ...@@ -2291,7 +2291,7 @@ sub process {
} }
} }
if ($seen != ($#chunks + 1)) { if ($seen != ($#chunks + 1)) {
WARN("braces {} are necessary for all arms of this statement\n" . $herectx); ERROR("braces {} are necessary for all arms of this statement\n" . $herectx);
} }
} }
} }
...@@ -2359,19 +2359,19 @@ sub process { ...@@ -2359,19 +2359,19 @@ sub process {
$herectx .= raw_line($linenr, $n) . "\n";; $herectx .= raw_line($linenr, $n) . "\n";;
} }
WARN("braces {} are necessary even for single statement blocks\n" . $herectx); ERROR("braces {} are necessary even for single statement blocks\n" . $herectx);
} }
} }
# no volatiles please # no volatiles please
my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); ERROR("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
} }
# warn about #if 0 # warn about #if 0
if ($line =~ /^.\s*\#\s*if\s+0\b/) { if ($line =~ /^.\s*\#\s*if\s+0\b/) {
WARN("if this code is redundant consider removing it\n" . ERROR("if this code is redundant consider removing it\n" .
$herecurr); $herecurr);
} }
...@@ -2379,7 +2379,7 @@ sub process { ...@@ -2379,7 +2379,7 @@ sub process {
if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
my $expr = $1; my $expr = $1;
if ($line =~ /\bg_free\(\Q$expr\E\);/) { if ($line =~ /\bg_free\(\Q$expr\E\);/) {
WARN("g_free(NULL) is safe this check is probably not required\n" . $hereprev); ERROR("g_free(NULL) is safe this check is probably not required\n" . $hereprev);
} }
} }
...@@ -2397,19 +2397,19 @@ sub process { ...@@ -2397,19 +2397,19 @@ sub process {
# check for memory barriers without a comment. # check for memory barriers without a comment.
if ($line =~ /\b(smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { if ($line =~ /\b(smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
if (!ctx_has_comment($first_line, $linenr)) { if (!ctx_has_comment($first_line, $linenr)) {
WARN("memory barrier without comment\n" . $herecurr); ERROR("memory barrier without comment\n" . $herecurr);
} }
} }
# check of hardware specific defines # check of hardware specific defines
# we have e.g. CONFIG_LINUX and CONFIG_WIN32 for common cases # we have e.g. CONFIG_LINUX and CONFIG_WIN32 for common cases
# where they might be necessary. # where they might be necessary.
if ($line =~ m@^.\s*\#\s*if.*\b__@) { if ($line =~ m@^.\s*\#\s*if.*\b__@) {
WARN("architecture specific defines should be avoided\n" . $herecurr); ERROR("architecture specific defines should be avoided\n" . $herecurr);
} }
# Check that the storage class is at the beginning of a declaration # Check that the storage class is at the beginning of a declaration
if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) { if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
WARN("storage class should be at the beginning of the declaration\n" . $herecurr) ERROR("storage class should be at the beginning of the declaration\n" . $herecurr)
} }
# check the location of the inline attribute, that it is between # check the location of the inline attribute, that it is between
...@@ -2421,7 +2421,7 @@ sub process { ...@@ -2421,7 +2421,7 @@ sub process {
# check for sizeof(&) # check for sizeof(&)
if ($line =~ /\bsizeof\s*\(\s*\&/) { if ($line =~ /\bsizeof\s*\(\s*\&/) {
WARN("sizeof(& should be avoided\n" . $herecurr); ERROR("sizeof(& should be avoided\n" . $herecurr);
} }
# check for new externs in .c files. # check for new externs in .c files.
...@@ -2438,40 +2438,40 @@ sub process { ...@@ -2438,40 +2438,40 @@ sub process {
if ($s =~ /^\s*;/ && if ($s =~ /^\s*;/ &&
$function_name ne 'uninitialized_var') $function_name ne 'uninitialized_var')
{ {
WARN("externs should be avoided in .c files\n" . $herecurr); ERROR("externs should be avoided in .c files\n" . $herecurr);
} }
if ($paren_space =~ /\n/) { if ($paren_space =~ /\n/) {
WARN("arguments for function declarations should follow identifier\n" . $herecurr); ERROR("arguments for function declarations should follow identifier\n" . $herecurr);
} }
} elsif ($realfile =~ /\.c$/ && defined $stat && } elsif ($realfile =~ /\.c$/ && defined $stat &&
$stat =~ /^.\s*extern\s+/) $stat =~ /^.\s*extern\s+/)
{ {
WARN("externs should be avoided in .c files\n" . $herecurr); ERROR("externs should be avoided in .c files\n" . $herecurr);
} }
# check for pointless casting of g_malloc return # check for pointless casting of g_malloc return
if ($line =~ /\*\s*\)\s*g_(try)?(m|re)alloc(0?)(_n)?\b/) { if ($line =~ /\*\s*\)\s*g_(try)?(m|re)alloc(0?)(_n)?\b/) {
if ($2 == 'm') { if ($2 == 'm') {
WARN("unnecessary cast may hide bugs, use g_$1new$3 instead\n" . $herecurr); ERROR("unnecessary cast may hide bugs, use g_$1new$3 instead\n" . $herecurr);
} else { } else {
WARN("unnecessary cast may hide bugs, use g_$1renew$3 instead\n" . $herecurr); ERROR("unnecessary cast may hide bugs, use g_$1renew$3 instead\n" . $herecurr);
} }
} }
# check for gcc specific __FUNCTION__ # check for gcc specific __FUNCTION__
if ($line =~ /__FUNCTION__/) { if ($line =~ /__FUNCTION__/) {
WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); ERROR("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
} }
# recommend qemu_strto* over strto* for numeric conversions # recommend qemu_strto* over strto* for numeric conversions
if ($line =~ /\b(strto[^kd].*?)\s*\(/) { if ($line =~ /\b(strto[^kd].*?)\s*\(/) {
WARN("consider using qemu_$1 in preference to $1\n" . $herecurr); ERROR("consider using qemu_$1 in preference to $1\n" . $herecurr);
} }
# check for module_init(), use category-specific init macros explicitly please # check for module_init(), use category-specific init macros explicitly please
if ($line =~ /^module_init\s*\(/) { if ($line =~ /^module_init\s*\(/) {
WARN("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr); ERROR("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr);
} }
# check for various ops structs, ensure they are const. # check for various ops structs, ensure they are const.
my $struct_ops = qr{AIOCBInfo| my $struct_ops = qr{AIOCBInfo|
...@@ -2496,7 +2496,7 @@ sub process { ...@@ -2496,7 +2496,7 @@ sub process {
VMStateInfo}x; VMStateInfo}x;
if ($line !~ /\bconst\b/ && if ($line !~ /\bconst\b/ &&
$line =~ /\b($struct_ops)\b/) { $line =~ /\b($struct_ops)\b/) {
WARN("struct $1 should normally be const\n" . ERROR("struct $1 should normally be const\n" .
$herecurr); $herecurr);
} }
...@@ -2506,14 +2506,14 @@ sub process { ...@@ -2506,14 +2506,14 @@ sub process {
$string = substr($rawline, $-[1], $+[1] - $-[1]); $string = substr($rawline, $-[1], $+[1] - $-[1]);
$string =~ s/%%/__/g; $string =~ s/%%/__/g;
if ($string =~ /(?<!%)%L[udi]/) { if ($string =~ /(?<!%)%L[udi]/) {
WARN("\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr); ERROR("\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
last; last;
} }
} }
# QEMU specific tests # QEMU specific tests
if ($rawline =~ /\b(?:Qemu|QEmu)\b/) { if ($rawline =~ /\b(?:Qemu|QEmu)\b/) {
WARN("use QEMU instead of Qemu or QEmu\n" . $herecurr); ERROR("use QEMU instead of Qemu or QEmu\n" . $herecurr);
} }
# Qemu error function tests # Qemu error function tests
...@@ -2530,7 +2530,7 @@ sub process { ...@@ -2530,7 +2530,7 @@ sub process {
error_report}x; error_report}x;
if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) { if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
WARN("Error messages should not contain newlines\n" . $herecurr); ERROR("Error messages should not contain newlines\n" . $herecurr);
} }
# Continue checking for error messages that contains newlines. This # Continue checking for error messages that contains newlines. This
...@@ -2551,7 +2551,7 @@ sub process { ...@@ -2551,7 +2551,7 @@ sub process {
} }
if ($rawlines[$i] =~ /\b(?:$qemu_error_funcs)\s*\(/) { if ($rawlines[$i] =~ /\b(?:$qemu_error_funcs)\s*\(/) {
WARN("Error messages should not contain newlines\n" . $herecurr); ERROR("Error messages should not contain newlines\n" . $herecurr);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册