From 369353832de39064d0e5b5553d1fcf2ea506df2e Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Tue, 17 Dec 2013 10:45:29 +1100 Subject: [PATCH] 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 Cc: Richard Weinberger Cc: Borislav Petkov Signed-off-by: Andrew Morton --- scripts/checkpatch.pl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9c9810030377..38be5d5b67ec 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2634,6 +2634,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 declarations of struct pci_device_id if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) { WARN("DEFINE_PCI_DEVICE_TABLE", -- 2.39.5