/*
                 * No need for a memory barrier here, as we are holding the tree
                 * lock and we only change the waitqueue while holding that lock
-                * (see wait_on_state()).
+                * (see wait_extent_bit()).
                 */
                ASSERT(!waitqueue_active(&state->wq));
                free_extent_state(state);
 
 }
 
-static void wait_on_state(struct extent_io_tree *tree,
-                         struct extent_state *state)
-               __releases(tree->lock)
-               __acquires(tree->lock)
-{
-       DEFINE_WAIT(wait);
-       prepare_to_wait(&state->wq, &wait, TASK_UNINTERRUPTIBLE);
-       spin_unlock(&tree->lock);
-       schedule();
-       spin_lock(&tree->lock);
-       finish_wait(&state->wq, &wait);
-}
-
 /*
  * Wait for one or more bits to clear on a range in the state tree.
  * The range [start, end] is inclusive.
                        goto out;
 
                if (state->state & bits) {
+                       DEFINE_WAIT(wait);
+
                        start = state->start;
                        refcount_inc(&state->refs);
-                       wait_on_state(tree, state);
+                       prepare_to_wait(&state->wq, &wait, TASK_UNINTERRUPTIBLE);
+                       spin_unlock(&tree->lock);
+                       schedule();
+                       spin_lock(&tree->lock);
+                       finish_wait(&state->wq, &wait);
                        free_extent_state(state);
                        goto again;
                }