lint/checkpatch: Add a check for use of self-assignments
This reduce the difference with linux v5.19-rc7. Signed-off-by: Elyes Haouas <ehaouas@noos.fr> Change-Id: If47a7826ee67a2be25a4caa2a447484e5f11411b Reviewed-on: https://review.coreboot.org/c/coreboot/+/65836 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin L Roth <gaumless@tutanota.com>
This commit is contained in:
committed by
Martin L Roth
parent
e83e090b05
commit
f9a3554a4a
@@ -4027,6 +4027,17 @@ sub process {
|
|||||||
#ignore lines not being added
|
#ignore lines not being added
|
||||||
next if ($line =~ /^[^\+]/);
|
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
|
# check for dereferences that span multiple lines
|
||||||
if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
|
if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
|
||||||
$line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
|
$line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
|
||||||
|
Reference in New Issue
Block a user