checkpatch: check for uncommented waitqueue_active()
authorJoe Perches <joe@perches.com>
Thu, 25 Jun 2015 22:02:46 +0000 (15:02 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 26 Jun 2015 00:00:41 +0000 (17:00 -0700)
Linus sayeth:

: Pretty much every single time people use this "if
: (waitqueue_active())" model, it tends to be a bug, because it means
: that there is zero serialization with people who are just about to go
: to sleep. It's fundamentally racy against all the "wait_event()" loops
: that carefully do memory barriers between testing conditions and going
: to sleep, because the memory barriers now don't exist on the waking
: side.
:
: So I'm making a new rule: if you use waitqueue_active(), I want an
: explanation for why it's not racy with the waiter. A big comment about
: the memory ordering, or about higher-level locks that are held by the
: caller, or something.

Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index c5ec977..3f2ff26 100755 (executable)
@@ -4898,6 +4898,13 @@ sub process {
                                     "memory barrier without comment\n" . $herecurr);
                        }
                }
+# check for waitqueue_active without a comment.
+               if ($line =~ /\bwaitqueue_active\s*\(/) {
+                       if (!ctx_has_comment($first_line, $linenr)) {
+                               WARN("WAITQUEUE_ACTIVE",
+                                    "waitqueue_active without comment\n" . $herecurr);
+                       }
+               }
 # check of hardware specific defines
                if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
                        CHK("ARCH_DEFINES",