summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2014-01-10 12:42:19 +1100
committerStephen Rothwell <sfr@canb.auug.org.au>2014-01-14 16:04:42 +1100
commitc84648549fcd10d5320033464ba6155926dd16e6 (patch)
treed4c83ff92f6d963dd47043d583c6b627478f079d
parente5e9b7b5a7827e60f23fabf9e404cb4ba8b211c8 (diff)
checkpatch.pl: check for function declarations without arguments
Functions like this one are evil: void foo() { ... } Because these functions allow variadic arguments without checking the arguments at all. Original patch by Richard Weinberger. Signed-off-by: Joe Perches <joe@perches.com> Cc: Richard Weinberger <richard@nod.at> Cc: Borislav Petkov <bp@alien8.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rwxr-xr-xscripts/checkpatch.pl9
1 files changed, 9 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d89e4299c19d..e530d90a0ef4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2638,6 +2638,15 @@ sub process {
$herecurr);
}
+# check for function declarations without arguments like "int foo()"
+ if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
+ if (ERROR("FUNCTION_WITHOUT_ARGS",
+ "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
+ $fix) {
+ $fixed[$linenr - 1] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
+ }
+ }
+
# check for uses of DEFINE_PCI_DEVICE_TABLE
if ($line =~ /\bDEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=/) {
if (WARN("DEFINE_PCI_DEVICE_TABLE",