checkpatch: Remove awareness of uninitialized_var() macro
authorKees Cook <keescook@chromium.org>
Wed, 3 Jun 2020 21:18:09 +0000 (14:18 -0700)
committerKees Cook <keescook@chromium.org>
Thu, 16 Jul 2020 19:32:26 +0000 (12:32 -0700)
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.

In preparation for removing[2] the[3] macro[4], partially revert
commit 16b7f3c89907 ("checkpatch: avoid warning about uninitialized_var()")
and remove all remaining mentions of uninitialized_var().

[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/

Signed-off-by: Kees Cook <keescook@chromium.org>
scripts/checkpatch.pl

index 4c820607540bf646f8defa5417876a987c1bc74d..60b737e222fec7c9ba17c194b42c3d127ca2763e 100755 (executable)
@@ -840,7 +840,6 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
 our $declaration_macros = qr{(?x:
        (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
        (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
-       (?:$Storage\s+)?${Type}\s+uninitialized_var\s*\(|
        (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
 )};
 
@@ -6330,8 +6329,7 @@ sub process {
                        if (defined $cond) {
                                substr($s, 0, length($cond), '');
                        }
-                       if ($s =~ /^\s*;/ &&
-                           $function_name ne 'uninitialized_var')
+                       if ($s =~ /^\s*;/)
                        {
                                WARN("AVOID_EXTERNS",
                                     "externs should be avoided in .c files\n" .  $herecurr);
@@ -6350,17 +6348,13 @@ sub process {
                }
 
 # check for function declarations that have arguments without identifier names
-# while avoiding uninitialized_var(x)
                if (defined $stat &&
-                   $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:($Ident)|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
-                   (!defined($1) ||
-                    (defined($1) && $1 ne "uninitialized_var")) &&
-                    $2 ne "void") {
-                       my $args = trim($2);
+                   $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
+                   $1 ne "void") {
+                       my $args = trim($1);
                        while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
                                my $arg = trim($1);
-                               if ($arg =~ /^$Type$/ &&
-                                       $arg !~ /enum\s+$Ident$/) {
+                               if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
                                        WARN("FUNCTION_ARGUMENTS",
                                             "function definition argument '$arg' should also have an identifier name\n" . $herecurr);
                                }