From: Joe Perches Date: Wed, 11 Sep 2013 21:23:58 +0000 (-0700) Subject: checkpatch: warn when using extern with function prototypes in .h files X-Git-Tag: v3.12-rc1~52^2~114 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=70dc8a48357ce630d8a76887a9a36f0d34c8caf2;p=~emulex%2Finfiniband.git checkpatch: warn when using extern with function prototypes in .h files Using the extern keyword on function prototypes is superfluous visual noise so suggest removing it. Using extern can cause unnecessary line wrapping at 80 columns and unnecessarily long multi-line function prototypes. Signed-off-by: Joe Perches Suggested-by: Hannes Frederic Sowa Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7c79c91662c..e2cb1f4621b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3878,6 +3878,16 @@ sub process { } } +# check for new externs in .h files. + if ($realfile =~ /\.h$/ && + $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) { + if (WARN("AVOID_EXTERNS", + "extern prototypes should be avoided in .h files\n" . $herecurr) && + $fix) { + $fixed[$linenr - 1] =~ s/(.*)\bextern\b\s*(.*)/$1$2/; + } + } + # check for new externs in .c files. if ($realfile =~ /\.c$/ && defined $stat && $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)