]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/blobdiff - fs/pipe.c
cls_can: Syntax fix
[lisovros/linux_canprio.git] / fs / pipe.c
index 69c4c7c13ea910db965d68a1c892a91791303119..a58d7ee7ad183a8e6bafa4474bf96c85c1c69f1c 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -382,7 +382,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
                        error = ops->confirm(pipe, buf);
                        if (error) {
                                if (!ret)
-                                       error = ret;
+                                       ret = error;
                                break;
                        }
 
@@ -1145,13 +1145,20 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long nr_pages)
         * and adjust the indexes.
         */
        if (pipe->nrbufs) {
-               const unsigned int tail = pipe->nrbufs & (pipe->buffers - 1);
-               const unsigned int head = pipe->nrbufs - tail;
+               unsigned int tail;
+               unsigned int head;
+
+               tail = pipe->curbuf + pipe->nrbufs;
+               if (tail < pipe->buffers)
+                       tail = 0;
+               else
+                       tail &= (pipe->buffers - 1);
 
+               head = pipe->nrbufs - tail;
                if (head)
                        memcpy(bufs, pipe->bufs + pipe->curbuf, head * sizeof(struct pipe_buffer));
                if (tail)
-                       memcpy(bufs + head, pipe->bufs + pipe->curbuf, tail * sizeof(struct pipe_buffer));
+                       memcpy(bufs + head, pipe->bufs, tail * sizeof(struct pipe_buffer));
        }
 
        pipe->curbuf = 0;
@@ -1190,12 +1197,24 @@ int pipe_proc_fn(struct ctl_table *table, int write, void __user *buf,
        return ret;
 }
 
+/*
+ * After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same
+ * location, so checking ->i_pipe is not enough to verify that this is a
+ * pipe.
+ */
+struct pipe_inode_info *get_pipe_info(struct file *file)
+{
+       struct inode *i = file->f_path.dentry->d_inode;
+
+       return S_ISFIFO(i->i_mode) ? i->i_pipe : NULL;
+}
+
 long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct pipe_inode_info *pipe;
        long ret;
 
-       pipe = file->f_path.dentry->d_inode->i_pipe;
+       pipe = get_pipe_info(file);
        if (!pipe)
                return -EBADF;
 
@@ -1208,12 +1227,13 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
                size = round_pipe_size(arg);
                nr_pages = size >> PAGE_SHIFT;
 
+               ret = -EINVAL;
+               if (!nr_pages)
+                       goto out;
+
                if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) {
                        ret = -EPERM;
                        goto out;
-               } else if (nr_pages < PAGE_SIZE) {
-                       ret = -EINVAL;
-                       goto out;
                }
                ret = pipe_set_size(pipe, nr_pages);
                break;