Skip to content

Commit d8b44b5

Browse files
committed
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 16b7f3c ("checkpatch: avoid warning about uninitialized_var()") and remove all remaining mentions of uninitialized_var(). [1] https://lore.kernel.org/lkml/[email protected]/ [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 <[email protected]>
1 parent fea1120 commit d8b44b5

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

scripts/checkpatch.pl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,6 @@ sub build_types {
840840
our $declaration_macros = qr{(?x:
841841
(?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
842842
(?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
843-
(?:$Storage\s+)?${Type}\s+uninitialized_var\s*\(|
844843
(?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
845844
)};
846845

@@ -6330,8 +6329,7 @@ sub process {
63306329
if (defined $cond) {
63316330
substr($s, 0, length($cond), '');
63326331
}
6333-
if ($s =~ /^\s*;/ &&
6334-
$function_name ne 'uninitialized_var')
6332+
if ($s =~ /^\s*;/)
63356333
{
63366334
WARN("AVOID_EXTERNS",
63376335
"externs should be avoided in .c files\n" . $herecurr);
@@ -6350,17 +6348,13 @@ sub process {
63506348
}
63516349

63526350
# check for function declarations that have arguments without identifier names
6353-
# while avoiding uninitialized_var(x)
63546351
if (defined $stat &&
6355-
$stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:($Ident)|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
6356-
(!defined($1) ||
6357-
(defined($1) && $1 ne "uninitialized_var")) &&
6358-
$2 ne "void") {
6359-
my $args = trim($2);
6352+
$stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
6353+
$1 ne "void") {
6354+
my $args = trim($1);
63606355
while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
63616356
my $arg = trim($1);
6362-
if ($arg =~ /^$Type$/ &&
6363-
$arg !~ /enum\s+$Ident$/) {
6357+
if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
63646358
WARN("FUNCTION_ARGUMENTS",
63656359
"function definition argument '$arg' should also have an identifier name\n" . $herecurr);
63666360
}

0 commit comments

Comments
 (0)