Elyes Haouas has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/70203 )
Change subject: lint/checkpatch: Update Check for illegal assignment in if conditional ......................................................................
lint/checkpatch: Update Check for illegal assignment in if conditional
This reduce the difference with linux v6.1-rc7.
Change-Id: I74709e68a62f9a88275ea67beba2933af0f3f519 Signed-off-by: Elyes Haouas ehaouas@noos.fr --- M util/lint/checkpatch.pl 1 file changed, 52 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/03/70203/1
diff --git a/util/lint/checkpatch.pl b/util/lint/checkpatch.pl index 296ab13..744c350 100755 --- a/util/lint/checkpatch.pl +++ b/util/lint/checkpatch.pl @@ -5228,10 +5228,34 @@ 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 @@ -5253,8 +5277,20 @@ $stat_real = "[...]\n$stat_real"; }
- ERROR("TRAILING_STATEMENTS", - "trailing statements should be on next line\n" . $herecurr . $stat_real); + if (ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr . $stat_real) && + !$fixed_assign_in_if && + $cond_lines == 0 && + $fix && $perl_version_ok && + $fixed[$fixlinenr] =~ /^+(\s*)((?:if|while|for)\s*$balanced_parens)\s*(.*)$/) { + my $indent = $1; + my $test = $2; + my $rest = rtrim($4); + if ($rest =~ /;$/) { + $fixed[$fixlinenr] = "+$indent$test"; + fix_insert_line($fixlinenr + 1, "$indent\t$rest"); + } + } } }