Revert "input: touch: raydium: V61.7 code drop"
[linux-3.10.git] / fs / pipe.c
index 161b209..0e0752e 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -21,6 +21,7 @@
 #include <linux/audit.h>
 #include <linux/syscalls.h>
 #include <linux/fcntl.h>
+#include <linux/aio.h>
 
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
@@ -55,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
 
 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
 {
-       if (pipe->inode)
+       if (pipe->files)
                mutex_lock_nested(&pipe->mutex, subclass);
 }
 
@@ -70,11 +71,21 @@ EXPORT_SYMBOL(pipe_lock);
 
 void pipe_unlock(struct pipe_inode_info *pipe)
 {
-       if (pipe->inode)
+       if (pipe->files)
                mutex_unlock(&pipe->mutex);
 }
 EXPORT_SYMBOL(pipe_unlock);
 
+static inline void __pipe_lock(struct pipe_inode_info *pipe)
+{
+       mutex_lock_nested(&pipe->mutex, I_MUTEX_PARENT);
+}
+
+static inline void __pipe_unlock(struct pipe_inode_info *pipe)
+{
+       mutex_unlock(&pipe->mutex);
+}
+
 void pipe_double_lock(struct pipe_inode_info *pipe1,
                      struct pipe_inode_info *pipe2)
 {
@@ -376,7 +387,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
 
        do_wakeup = 0;
        ret = 0;
-       pipe_lock(pipe);
+       __pipe_lock(pipe);
        for (;;) {
                int bufs = pipe->nrbufs;
                if (bufs) {
@@ -464,7 +475,7 @@ redo:
                }
                pipe_wait(pipe);
        }
-       pipe_unlock(pipe);
+       __pipe_unlock(pipe);
 
        /* Signal writers asynchronously that there is more room. */
        if (do_wakeup) {
@@ -500,7 +511,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
 
        do_wakeup = 0;
        ret = 0;
-       pipe_lock(pipe);
+       __pipe_lock(pipe);
 
        if (!pipe->readers) {
                send_sig(SIGPIPE, current, 0);
@@ -647,7 +658,7 @@ redo2:
                pipe->waiting_writers--;
        }
 out:
-       pipe_unlock(pipe);
+       __pipe_unlock(pipe);
        if (do_wakeup) {
                wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM);
                kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
@@ -667,7 +678,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
        switch (cmd) {
                case FIONREAD:
-                       pipe_lock(pipe);
+                       __pipe_lock(pipe);
                        count = 0;
                        buf = pipe->curbuf;
                        nrbufs = pipe->nrbufs;
@@ -675,7 +686,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                                count += pipe->bufs[buf].len;
                                buf = (buf+1) & (pipe->buffers - 1);
                        }
-                       pipe_unlock(pipe);
+                       __pipe_unlock(pipe);
 
                        return put_user(count, (int __user *)arg);
                default:
@@ -715,13 +726,27 @@ pipe_poll(struct file *filp, poll_table *wait)
        return mask;
 }
 
+static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
+{
+       int kill = 0;
+
+       spin_lock(&inode->i_lock);
+       if (!--pipe->files) {
+               inode->i_pipe = NULL;
+               kill = 1;
+       }
+       spin_unlock(&inode->i_lock);
+
+       if (kill)
+               free_pipe_info(pipe);
+}
+
 static int
 pipe_release(struct inode *inode, struct file *file)
 {
-       struct pipe_inode_info *pipe = inode->i_pipe;
-       int kill = 0;
+       struct pipe_inode_info *pipe = file->private_data;
 
-       pipe_lock(pipe);
+       __pipe_lock(pipe);
        if (file->f_mode & FMODE_READ)
                pipe->readers--;
        if (file->f_mode & FMODE_WRITE)
@@ -732,17 +757,9 @@ pipe_release(struct inode *inode, struct file *file)
                kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
                kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
        }
-       spin_lock(&inode->i_lock);
-       if (!--pipe->files) {
-               inode->i_pipe = NULL;
-               kill = 1;
-       }
-       spin_unlock(&inode->i_lock);
-       pipe_unlock(pipe);
-
-       if (kill)
-               __free_pipe_info(pipe);
+       __pipe_unlock(pipe);
 
+       put_pipe_info(inode, pipe);
        return 0;
 }
 
@@ -752,7 +769,7 @@ pipe_fasync(int fd, struct file *filp, int on)
        struct pipe_inode_info *pipe = filp->private_data;
        int retval = 0;
 
-       pipe_lock(pipe);
+       __pipe_lock(pipe);
        if (filp->f_mode & FMODE_READ)
                retval = fasync_helper(fd, filp, on, &pipe->fasync_readers);
        if ((filp->f_mode & FMODE_WRITE) && retval >= 0) {
@@ -761,11 +778,11 @@ pipe_fasync(int fd, struct file *filp, int on)
                        /* this can happen only if on == T */
                        fasync_helper(-1, filp, 0, &pipe->fasync_readers);
        }
-       pipe_unlock(pipe);
+       __pipe_unlock(pipe);
        return retval;
 }
 
-struct pipe_inode_info * alloc_pipe_info(struct inode *inode)
+struct pipe_inode_info *alloc_pipe_info(void)
 {
        struct pipe_inode_info *pipe;
 
@@ -775,7 +792,6 @@ struct pipe_inode_info * alloc_pipe_info(struct inode *inode)
                if (pipe->bufs) {
                        init_waitqueue_head(&pipe->wait);
                        pipe->r_counter = pipe->w_counter = 1;
-                       pipe->inode = inode;
                        pipe->buffers = PIPE_DEF_BUFFERS;
                        mutex_init(&pipe->mutex);
                        return pipe;
@@ -786,7 +802,7 @@ struct pipe_inode_info * alloc_pipe_info(struct inode *inode)
        return NULL;
 }
 
-void __free_pipe_info(struct pipe_inode_info *pipe)
+void free_pipe_info(struct pipe_inode_info *pipe)
 {
        int i;
 
@@ -801,12 +817,6 @@ void __free_pipe_info(struct pipe_inode_info *pipe)
        kfree(pipe);
 }
 
-void free_pipe_info(struct inode *inode)
-{
-       __free_pipe_info(inode->i_pipe);
-       inode->i_pipe = NULL;
-}
-
 static struct vfsmount *pipe_mnt __read_mostly;
 
 /*
@@ -832,7 +842,7 @@ static struct inode * get_pipe_inode(void)
 
        inode->i_ino = get_next_ino();
 
-       pipe = alloc_pipe_info(inode);
+       pipe = alloc_pipe_info();
        if (!pipe)
                goto fail_iput;
 
@@ -902,12 +912,12 @@ int create_pipe_files(struct file **res, int flags)
 err_file:
        put_filp(f);
 err_dentry:
-       free_pipe_info(inode);
+       free_pipe_info(inode->i_pipe);
        path_put(&path);
        return err;
 
 err_inode:
-       free_pipe_info(inode);
+       free_pipe_info(inode->i_pipe);
        iput(inode);
        return err;
 }
@@ -1010,7 +1020,6 @@ static int fifo_open(struct inode *inode, struct file *filp)
 {
        struct pipe_inode_info *pipe;
        bool is_pipe = inode->i_sb->s_magic == PIPEFS_MAGIC;
-       int kill = 0;
        int ret;
 
        filp->f_version = 0;
@@ -1022,7 +1031,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
                spin_unlock(&inode->i_lock);
        } else {
                spin_unlock(&inode->i_lock);
-               pipe = alloc_pipe_info(inode);
+               pipe = alloc_pipe_info();
                if (!pipe)
                        return -ENOMEM;
                pipe->files = 1;
@@ -1030,7 +1039,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
                if (unlikely(inode->i_pipe)) {
                        inode->i_pipe->files++;
                        spin_unlock(&inode->i_lock);
-                       __free_pipe_info(pipe);
+                       free_pipe_info(pipe);
                        pipe = inode->i_pipe;
                } else {
                        inode->i_pipe = pipe;
@@ -1040,7 +1049,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
        filp->private_data = pipe;
        /* OK, we have a pipe and it's pinned down */
 
-       pipe_lock(pipe);
+       __pipe_lock(pipe);
 
        /* We can only do regular read/write on fifos */
        filp->f_mode &= (FMODE_READ | FMODE_WRITE);
@@ -1110,7 +1119,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
        }
 
        /* Ok! */
-       pipe_unlock(pipe);
+       __pipe_unlock(pipe);
        return 0;
 
 err_rd:
@@ -1126,15 +1135,9 @@ err_wr:
        goto err;
 
 err:
-       spin_lock(&inode->i_lock);
-       if (!--pipe->files) {
-               inode->i_pipe = NULL;
-               kill = 1;
-       }
-       spin_unlock(&inode->i_lock);
-       pipe_unlock(pipe);
-       if (kill)
-               __free_pipe_info(pipe);
+       __pipe_unlock(pipe);
+
+       put_pipe_info(inode, pipe);
        return ret;
 }
 
@@ -1248,7 +1251,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
        if (!pipe)
                return -EBADF;
 
-       pipe_lock(pipe);
+       __pipe_lock(pipe);
 
        switch (cmd) {
        case F_SETPIPE_SZ: {
@@ -1277,7 +1280,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 
 out:
-       pipe_unlock(pipe);
+       __pipe_unlock(pipe);
        return ret;
 }