[PATCH] scripts/checkpatch.pl: Add WARN on sizeof(&
From: Joe Perches
Date: Sat Oct 03 2009 - 21:14:14 EST
On Sat, 2009-10-03 at 17:38 +0200, Jan Ceuleers wrote:
> David Miller wrote:
> > Any time you see "&" in a sizeof() expression, it's almost
> > certainly a bug. Something for the folks with automated
> > tools to look for if they haven't already :-)
>
> Your remark prompted me to find four more instances of such bugs
> (none of which in the networking bits). I have submitted patches.
Perhaps a checkpatch test.
---
sizeof(&foo) is frequently an error. Warn on its use.
Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 87bbb8b..596dd72 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2534,6 +2534,11 @@ sub process {
WARN("plain inline is preferred over $1\n" . $herecurr);
}
+# check for sizeof(&)
+ if ($line =~ /\bsizeof\s*\(\s*\&/) {
+ WARN("sizeof(& should be avoided\n" . $herecurr);
+ }
+
# check for new externs in .c files.
if ($realfile =~ /\.c$/ && defined $stat &&
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
--
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/