summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2014-12-10 15:52:02 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-10 17:41:12 -0800
commitb75ac618df751b927469ddbca63cf151a62f0f9d (patch)
treefbc657be2fa3993e8639d5e083f4962811b025c5 /scripts
parent90ad30e5b2a759333f06eee64e59a0d886d02036 (diff)
downloadlinux-b75ac618df751b927469ddbca63cf151a62f0f9d.tar.gz
linux-b75ac618df751b927469ddbca63cf151a62f0f9d.tar.bz2
linux-b75ac618df751b927469ddbca63cf151a62f0f9d.zip
checkpatch: add --strict "pointer comparison to NULL" test
It seems there are more and more uses of "if (!ptr)" in preference to "if (ptr == NULL)" so add a --strict test to emit a message when using the latter form. This also finds (ptr != NULL). Fix it too if desired. Signed-off-by: Joe Perches <joe@perches.com> Cc: Dan Carpenter <dan.carpenter@oracle.com> Cc: Greg KH <gregkh@linuxfoundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl14
1 files changed, 14 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5e63dce2e428..6d85c7b1b27e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4522,6 +4522,20 @@ sub process {
"Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
}
+# check for pointer comparisons to NULL
+ if ($^V && $^V ge 5.10.0) {
+ while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
+ my $val = $1;
+ my $equal = "!";
+ $equal = "" if ($4 eq "!=");
+ if (CHK("COMPARISON_TO_NULL",
+ "Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
+ }
+ }
+ }
+
# check for bad placement of section $InitAttribute (e.g.: __initdata)
if ($line =~ /(\b$InitAttribute\b)/) {
my $attr = $1;