[PATCH] checkpatch: consolidate if (foo) bar(NULL) checks

From: Andy Whitcroft
Date: Tue Nov 20 2012 - 09:27:59 EST


Signed-off-by: Andy Whitcroft <apw@xxxxxxxxxxxxx>
---
scripts/checkpatch.pl | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 313617b..6660246 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3229,19 +3229,16 @@ sub process {
my $expr = '\s*\(\s*' . quotemeta($1) . '\s*\)\s*;';

# check for needless kfree() checks
- if ($line =~ /\bkfree$expr/) {
- WARN("NEEDLESS_KFREE",
- "kfree(NULL) is safe this check is probably not required\n" . $hereprev);
- }
# check for needless usb_free_urb() checks
- if ($line =~ /\busb_free_urb$expr/) {
- WARN("NEEDLESS_USB_FREE_URB",
- "usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev);
- }
# check for needless debugfs_remove() and debugfs_remove_recursive*() checks
- if ($line =~ /\b(debugfs_remove(?:_recursive)?)$expr/) {
- WARN("NEEDLESS_DEBUGFS_REMOVE",
- "$1(NULL) is safe this check is probably not required\n" . $hereprev);
+ if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?)$expr/) {
+ my $func = $1;
+ my $func_capacity = "NEEDLESS_$1";
+
+ $func_capacity =~ s/(.$)/\U$1\E/;
+
+ WARN($func_capacity,
+ "$func(NULL) is safe this check is probably not required\n" . $hereprev);
}
}

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/