From f9a3554a4afd88dd2a606cf97e315bcdbe1fe8a6 Mon Sep 17 00:00:00 2001 From: Elyes Haouas Date: Wed, 13 Jul 2022 18:03:47 +0200 Subject: [PATCH] lint/checkpatch: Add a check for use of self-assignments This reduce the difference with linux v5.19-rc7. Signed-off-by: Elyes Haouas Change-Id: If47a7826ee67a2be25a4caa2a447484e5f11411b Reviewed-on: https://review.coreboot.org/c/coreboot/+/65836 Tested-by: build bot (Jenkins) Reviewed-by: Martin L Roth --- util/lint/checkpatch.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/lint/checkpatch.pl b/util/lint/checkpatch.pl index 86fc9b25c2..2fc3c14dec 100755 --- a/util/lint/checkpatch.pl +++ b/util/lint/checkpatch.pl @@ -4027,6 +4027,17 @@ sub process { #ignore lines not being added next if ($line =~ /^[^\+]/); +# check for self assignments used to avoid compiler warnings +# e.g.: int foo = foo, *bar = NULL; +# struct foo bar = *(&(bar)); + if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) { + my $var = $1; + if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) { + WARN("SELF_ASSIGNMENT", + "Do not use self-assignments to avoid compiler warnings\n" . $herecurr); + } + } + # check for dereferences that span multiple lines if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ && $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {