splice: move permission hook out of splice_direct_to_actor()
[linux-block.git] / fs / splice.c
index 6e917db6f49aabbcfaaae5f9c39d053935d49dab..6fc2c27e9520750100e1780b7f200b3034a916c2 100644 (file)
@@ -944,27 +944,15 @@ static void do_splice_eof(struct splice_desc *sd)
                sd->splice_eof(sd);
 }
 
-/**
- * vfs_splice_read - Read data from a file and splice it into a pipe
- * @in:                File to splice from
- * @ppos:      Input file offset
- * @pipe:      Pipe to splice to
- * @len:       Number of bytes to splice
- * @flags:     Splice modifier flags (SPLICE_F_*)
- *
- * Splice the requested amount of data from the input file to the pipe.  This
- * is synchronous as the caller must hold the pipe lock across the entire
- * operation.
- *
- * If successful, it returns the amount of data spliced, 0 if it hit the EOF or
- * a hole and a negative error code otherwise.
+/*
+ * Callers already called rw_verify_area() on the entire range.
+ * No need to call it for sub ranges.
  */
-long vfs_splice_read(struct file *in, loff_t *ppos,
-                    struct pipe_inode_info *pipe, size_t len,
-                    unsigned int flags)
+static long do_splice_read(struct file *in, loff_t *ppos,
+                          struct pipe_inode_info *pipe, size_t len,
+                          unsigned int flags)
 {
        unsigned int p_space;
-       int ret;
 
        if (unlikely(!(in->f_mode & FMODE_READ)))
                return -EBADF;
@@ -975,10 +963,6 @@ long vfs_splice_read(struct file *in, loff_t *ppos,
        p_space = pipe->max_usage - pipe_occupancy(pipe->head, pipe->tail);
        len = min_t(size_t, len, p_space << PAGE_SHIFT);
 
-       ret = rw_verify_area(READ, in, ppos, len);
-       if (unlikely(ret < 0))
-               return ret;
-
        if (unlikely(len > MAX_RW_COUNT))
                len = MAX_RW_COUNT;
 
@@ -992,6 +976,34 @@ long vfs_splice_read(struct file *in, loff_t *ppos,
                return copy_splice_read(in, ppos, pipe, len, flags);
        return in->f_op->splice_read(in, ppos, pipe, len, flags);
 }
+
+/**
+ * vfs_splice_read - Read data from a file and splice it into a pipe
+ * @in:                File to splice from
+ * @ppos:      Input file offset
+ * @pipe:      Pipe to splice to
+ * @len:       Number of bytes to splice
+ * @flags:     Splice modifier flags (SPLICE_F_*)
+ *
+ * Splice the requested amount of data from the input file to the pipe.  This
+ * is synchronous as the caller must hold the pipe lock across the entire
+ * operation.
+ *
+ * If successful, it returns the amount of data spliced, 0 if it hit the EOF or
+ * a hole and a negative error code otherwise.
+ */
+long vfs_splice_read(struct file *in, loff_t *ppos,
+                    struct pipe_inode_info *pipe, size_t len,
+                    unsigned int flags)
+{
+       int ret;
+
+       ret = rw_verify_area(READ, in, ppos, len);
+       if (unlikely(ret < 0))
+               return ret;
+
+       return do_splice_read(in, ppos, pipe, len, flags);
+}
 EXPORT_SYMBOL_GPL(vfs_splice_read);
 
 /**
@@ -1066,7 +1078,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
                size_t read_len;
                loff_t pos = sd->pos, prev_pos = pos;
 
-               ret = vfs_splice_read(in, &pos, pipe, len, flags);
+               ret = do_splice_read(in, &pos, pipe, len, flags);
                if (unlikely(ret <= 0))
                        goto read_failure;