mutex_lock(&pipe->inode->i_mutex);
 
        for (;;) {
-               int bufs;
-
                if (!pipe->readers) {
                        send_sig(SIGPIPE, current, 0);
                        if (!ret)
                        break;
                }
 
-               bufs = pipe->nrbufs;
-               if (bufs < PIPE_BUFFERS) {
-                       int newbuf = (pipe->curbuf + bufs) & (PIPE_BUFFERS - 1);
+               if (pipe->nrbufs < PIPE_BUFFERS) {
+                       int newbuf = (pipe->curbuf + pipe->nrbufs) & (PIPE_BUFFERS - 1);
                        struct pipe_buffer *buf = pipe->bufs + newbuf;
                        struct page *page = pages[i++];
                        unsigned long this_len;
                        buf->offset = offset;
                        buf->len = this_len;
                        buf->ops = &page_cache_pipe_buf_ops;
-                       pipe->nrbufs = ++bufs;
-                       do_wakeup = 1;
+                       pipe->nrbufs++;
+                       if (pipe->inode)
+                               do_wakeup = 1;
 
                        ret += this_len;
                        len -= this_len;
                                break;
                        if (!len)
                                break;
-                       if (bufs < PIPE_BUFFERS)
+                       if (pipe->nrbufs < PIPE_BUFFERS)
                                continue;
 
                        break;
                mutex_lock(&pipe->inode->i_mutex);
 
        for (;;) {
-               int bufs = pipe->nrbufs;
-
-               if (bufs) {
-                       int curbuf = pipe->curbuf;
-                       struct pipe_buffer *buf = pipe->bufs + curbuf;
+               if (pipe->nrbufs) {
+                       struct pipe_buffer *buf = pipe->bufs + pipe->curbuf;
                        struct pipe_buf_operations *ops = buf->ops;
 
                        sd.len = buf->len;
                        if (!buf->len) {
                                buf->ops = NULL;
                                ops->release(pipe, buf);
-                               curbuf = (curbuf + 1) & (PIPE_BUFFERS - 1);
-                               pipe->curbuf = curbuf;
-                               pipe->nrbufs = --bufs;
-                               do_wakeup = 1;
+                               pipe->curbuf = (pipe->curbuf + 1) & (PIPE_BUFFERS - 1);
+                               pipe->nrbufs--;
+                               if (pipe->inode)
+                                       do_wakeup = 1;
                        }
 
                        sd.pos += sd.len;
                                break;
                }
 
-               if (bufs)
+               if (pipe->nrbufs)
                        continue;
                if (!pipe->writers)
                        break;
                kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
        }
 
-       mutex_lock(&out->f_mapping->host->i_mutex);
        out->f_pos = sd.pos;
-       mutex_unlock(&out->f_mapping->host->i_mutex);
        return ret;
 
 }