]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
checkpatch: check for spin_is_locked()
authorAndi Kleen <ak@linux.intel.com>
Wed, 4 Apr 2012 00:08:27 +0000 (10:08 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 11 Apr 2012 04:45:51 +0000 (14:45 +1000)
spin_is_locked() is usually misued. In checkpatch.pl:

- warn when it is used at all

- error out when it is asserted on free, because that's usually broken
  (e.g.  doesn't work on on uni processor builds).  Recommend
  lockdep_assert_held() instead.

[joe@perches.com: some improvements]
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
scripts/checkpatch.pl

index de639eeeed506b76b54220e7e7f86ed879af02a1..22b43baf6ee0ae810e50b3a9a0a5c0ac26450120 100755 (executable)
@@ -3458,6 +3458,20 @@ sub process {
                        }
                }
 
+# spin_is_locked is usually misused. warn about it.
+               if ($line =~ /\bspin_is_locked\s*\(/) {
+                       # BUG_ON/WARN_ON(!spin_is_locked() is generally a bug
+                       if ($line =~ /(BUG_ON|WARN_ON|ASSERT)\s*\(!spin_is_locked/) {
+                               ERROR("SPIN_IS_LOCKED",
+                                    "Use lockdep_assert_held() instead of asserts on !spin_is_locked\n"
+                                     . $herecurr);
+                       } else {
+                               WARN("SPIN_IS_LOCKED",
+                            "spin_is_locked is usually misused. See Documentation/spinlocks.txt\n"
+                                       . $herecurr)
+                       }
+               }
+
 # check for lockdep_set_novalidate_class
                if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
                    $line =~ /__lockdep_no_validate__\s*\)/ ) {