]> git.baikalelectronics.ru Git - kernel.git/commitdiff
splice: stop abusing iov_iter_advance() to flush a pipe
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 12 Jun 2022 20:07:49 +0000 (16:07 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 9 Aug 2022 02:37:16 +0000 (22:37 -0400)
Use pipe_discard_from() explicitly in generic_file_read_iter(); don't bother
with rather non-obvious use of iov_iter_advance() in there.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/splice.c

index 93a2c9bf624941af7791ab2c58871e855913ba6e..877290500050865bfde7dbef4a00170ea0936b50 100644 (file)
@@ -301,11 +301,9 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
 {
        struct iov_iter to;
        struct kiocb kiocb;
-       unsigned int i_head;
        int ret;
 
        iov_iter_pipe(&to, READ, pipe, len);
-       i_head = to.head;
        init_sync_kiocb(&kiocb, in);
        kiocb.ki_pos = *ppos;
        ret = call_read_iter(in, &kiocb, &to);
@@ -313,9 +311,8 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
                *ppos = kiocb.ki_pos;
                file_accessed(in);
        } else if (ret < 0) {
-               to.head = i_head;
-               to.iov_offset = 0;
-               iov_iter_advance(&to, 0); /* to free what was emitted */
+               /* free what was emitted */
+               pipe_discard_from(pipe, to.start_head);
                /*
                 * callers of ->splice_read() expect -EAGAIN on
                 * "can't put anything in there", rather than -EFAULT.