if (!sbi)
                goto out_kill_sb;
 
-       if (!sbi->catatonic)
-               autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
+       /* Free wait queues, close pipe */
+       autofs4_catatonic_mode(sbi);
 
        /* Clean up and release dangling references */
        autofs4_force_release(sbi);
 
 {
        struct autofs_wait_queue *wq, *nwq;
 
+       mutex_lock(&sbi->wq_mutex);
+       if (sbi->catatonic) {
+               mutex_unlock(&sbi->wq_mutex);
+               return;
+       }
+
        DPRINTK("entering catatonic mode");
 
        sbi->catatonic = 1;
        }
        fput(sbi->pipe);        /* Close the pipe */
        sbi->pipe = NULL;
+       sbi->pipefd = -1;
+       mutex_unlock(&sbi->wq_mutex);
 }
 
 static int autofs4_write(struct file *file, const void *addr, int bytes)
                        wq->name.name, notify);
        }
 
-       /* wq->name is NULL if and only if the lock is already released */
-
-       if (sbi->catatonic) {
-               /* We might have slept, so check again for catatonic mode */
-               wq->status = -ENOENT;
-               if (wq->name.name) {
-                       kfree(wq->name.name);
-                       wq->name.name = NULL;
-               }
-       }
-
+       /*
+        * wq->name.name is NULL iff the lock is already released
+        * or the mount has been made catatonic.
+        */
        if (wq->name.name) {
                /* Block all but "shutdown" signals while waiting */
                sigset_t oldset;