summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorElyes Haouas <ehaouas@noos.fr>2022-07-13 18:03:47 +0200
committerMartin L Roth <gaumless@tutanota.com>2022-07-19 01:48:24 +0000
commitf9a3554a4afd88dd2a606cf97e315bcdbe1fe8a6 (patch)
tree534eb23bc4459426244710944c92de22d1b75eee /util
parente83e090b05b6aa0d8c1816e626836f712ecb9490 (diff)
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>
Diffstat (limited to 'util')
-rwxr-xr-xutil/lint/checkpatch.pl11
1 files changed, 11 insertions, 0 deletions
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/) {