[PATCH 5/5] checkpatch: fix false EXPORT_SYMBOL warning

From: Daniel Walker
Date: Mon Sep 21 2009 - 22:15:41 EST


Ingo reported that the following lines triggered a false warning,

static struct lock_class_key rcu_lock_key;
struct lockdep_map rcu_lock_map =
STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key);
EXPORT_SYMBOL_GPL(rcu_lock_map);

from kernel/rcutree.c , and the false warning looked like this,

WARNING: EXPORT_SYMBOL(foo); should immediately follow its
function/variable
+EXPORT_SYMBOL_GPL(rcu_lock_map);

This change corrects this. It was caused because checkpatch doesn't check
more than one line above the "EXPORT_SYMBOL" for additional context (ie.
variable name, or initializer). Things are somewhat more complicated
because STATIC_LOCKDEP_MAP_INIT() doesn't accept the variable name that
is being initialized. I just added another check that checks two lines
above "EXPORT_SYMBOL" for the variable declaration.

Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Daniel Walker <dwalker@xxxxxxxxxx>
---
scripts/checkpatch.pl | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index fd4fe03..9996bfb 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1629,7 +1629,7 @@ sub process {

# check for initialisation to aggregates open brace on the next line
if (($prevline =~ /$Declare\s*$Ident\s*=\s*$/ || $prevline =~ /$Attribute\s*=\s*$/) &&
- $line =~ /^.\s*{/) {
+ $line =~ /^.\s*{/) {
ERROR("that open brace { should be on the previous line\n" . $hereprev);
}

@@ -1665,7 +1665,9 @@ sub process {
^.LIST_HEAD\(\Q$name\E\)|
^.$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=|\[)
- )/x) {
+ )/x && defined $lines[$linenr - 3] &&
+ $lines[$linenr - 3] !~ /(?:\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=|\[))/
+ ) {
WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
}
}
--
1.5.6.3

--
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/