The patch titled Subject: checkpatch: warn on self-assignments has been added to the -mm tree. Its filename is checkpatch-warn-on-self-assignments.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/checkpatch-warn-on-self-assignments.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/checkpatch-warn-on-self-assignments.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Joe Perches <joe@xxxxxxxxxxx> Subject: checkpatch: warn on self-assignments The uninitialized_var() macro was removed recently via commit 63a0895d960a ("compiler: Remove uninitialized_var() macro") as it's not a particularly useful warning and its use can "paper over real bugs". Add a checkpatch test to warn on self-assignments as a means to avoid compiler warnings and as a back-door mechanism to reproduce the old uninitialized_var macro behavior. Link: https://lkml.kernel.org/r/afc2cffdd315d3e4394af149278df9e8af7f49f4.camel@xxxxxxxxxxx Signed-off-by: Joe Perches <joe@xxxxxxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Cc: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx> Cc: Denis Efremov <efremov@xxxxxxxxx> Cc: Julia Lawall <julia.lawall@xxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- scripts/checkpatch.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/scripts/checkpatch.pl~checkpatch-warn-on-self-assignments +++ a/scripts/checkpatch.pl @@ -3901,6 +3901,17 @@ sub process { #ignore lines not being added next if ($line =~ /^[^\+]/); +# check for self assigments 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/) { _ Patches currently in -mm which might be from joe@xxxxxxxxxxx are checkpatch-test-git_dir-changes.patch get_maintainer-add-test-for-file-in-vcs.patch get_maintainer-exclude-maintainers-files-from-git-fallback.patch checkpatch-move-repeated-word-test.patch checkpatch-add-test-for-comma-use-that-should-be-semicolon.patch checkpatch-warn-on-self-assignments.patch