scripts: checkpatch.pl: fix constant comparison false positives

Comparisons that have constants on both side of the operator
were getting flagged incorrectly. Adjust the check so that
pure constant comparisons are not flagged, reducing false
positives.

WARNING:CONSTANT_COMPARISON: \
  Comparisons should place the constant on the right side of \
  the test
+BUILD_ASSERT(CONFIG_MAX_PTHREAD_COUNT == \
  CONFIG_MAX_PTHREAD_MUTEX_COUNT - 1);

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This commit is contained in:
Christopher Friedt 2024-01-19 07:37:33 -05:00 committed by Chris Friedt
parent 248324b67a
commit a37254140b

View file

@ -5004,6 +5004,7 @@ sub process {
# only fix matches surrounded by parentheses to avoid incorrect # only fix matches surrounded by parentheses to avoid incorrect
# conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5" # conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
if ($perl_version_ok && if ($perl_version_ok &&
!($line =~ /^\+(.*)($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*(.*)($Constant|[A-Z_][A-Z0-9_]*)(.*)/) &&
$line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) { $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
my $lead = $1; my $lead = $1;
my $const = $2; my $const = $2;