diff options
author | Elyes Haouas <ehaouas@noos.fr> | 2023-08-01 18:12:47 +0200 |
---|---|---|
committer | Elyes Haouas <ehaouas@noos.fr> | 2023-08-09 20:40:10 +0000 |
commit | d2bb4858f3246fc7b6af74a28cd5f14cdee2c5a4 (patch) | |
tree | 32ec8aff4a342d6718994c7402962c873edb0f88 | |
parent | a9e4567c4b0dead27bcd3ed3044931eb5d81bec1 (diff) |
lint/checkpatch: Update 'check for illegal assignment in if conditional'
This reduce the difference with linux v6.5-rc4.
Change-Id: I63b3561471d3bd0ebfe7e5733c6dd6fb673904e0
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/65829
Reviewed-by: Martin L Roth <gaumless@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
-rwxr-xr-x | util/lint/checkpatch.pl | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/util/lint/checkpatch.pl b/util/lint/checkpatch.pl index c2efdbcd50..120e57ea73 100755 --- a/util/lint/checkpatch.pl +++ b/util/lint/checkpatch.pl @@ -5180,10 +5180,34 @@ sub process { defined($stat) && defined($cond) && $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { my ($s, $c) = ($stat, $cond); + my $fixed_assign_in_if = 0; if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { - ERROR("ASSIGN_IN_IF", - "do not use assignment in if condition\n" . $herecurr); + if (ERROR("ASSIGN_IN_IF", + "do not use assignment in if condition\n" . $herecurr) && + $fix && $perl_version_ok) { + if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) { + my $space = $1; + my $not = $2; + my $statement = $3; + my $assigned = $4; + my $test = $8; + my $against = $9; + my $brace = $15; + fix_delete_line($fixlinenr, $rawline); + fix_insert_line($fixlinenr, "$space$statement;"); + my $newline = "${space}if ("; + $newline .= '!' if defined($not); + $newline .= '(' if (defined $not && defined($test) && defined($against)); + $newline .= "$assigned"; + $newline .= " $test $against" if (defined($test) && defined($against)); + $newline .= ')' if (defined $not && defined($test) && defined($against)); + $newline .= ')'; + $newline .= " {" if (defined($brace)); + fix_insert_line($fixlinenr + 1, $newline); + $fixed_assign_in_if = 1; + } + } } # Find out what is on the end of the line after the |