Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

checkpatch: Remove awareness of uninitialized_var() macro

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>

+5 -11
+5 -11
scripts/checkpatch.pl
··· 840 840 our $declaration_macros = qr{(?x: 841 841 (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(| 842 842 (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(| 843 - (?:$Storage\s+)?${Type}\s+uninitialized_var\s*\(| 844 843 (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\( 845 844 )}; 846 845 ··· 6329 6330 if (defined $cond) { 6330 6331 substr($s, 0, length($cond), ''); 6331 6332 } 6332 - if ($s =~ /^\s*;/ && 6333 - $function_name ne 'uninitialized_var') 6333 + if ($s =~ /^\s*;/) 6334 6334 { 6335 6335 WARN("AVOID_EXTERNS", 6336 6336 "externs should be avoided in .c files\n" . $herecurr); ··· 6348 6350 } 6349 6351 6350 6352 # check for function declarations that have arguments without identifier names 6351 - # while avoiding uninitialized_var(x) 6352 6353 if (defined $stat && 6353 - $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:($Ident)|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s && 6354 - (!defined($1) || 6355 - (defined($1) && $1 ne "uninitialized_var")) && 6356 - $2 ne "void") { 6357 - my $args = trim($2); 6354 + $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s && 6355 + $1 ne "void") { 6356 + my $args = trim($1); 6358 6357 while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) { 6359 6358 my $arg = trim($1); 6360 - if ($arg =~ /^$Type$/ && 6361 - $arg !~ /enum\s+$Ident$/) { 6359 + if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) { 6362 6360 WARN("FUNCTION_ARGUMENTS", 6363 6361 "function definition argument '$arg' should also have an identifier name\n" . $herecurr); 6364 6362 }