]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs: Allow a NULL pos pointer to __kernel_read
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Sat, 3 Oct 2020 02:55:23 +0000 (03:55 +0100)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 15 Oct 2020 18:20:42 +0000 (14:20 -0400)
Match the behaviour of new_sync_read() and __kernel_write().

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/read_write.c

index 516eb51af70e256a9759fc90f574d4bea1a91145..498cc00f3c0871eb7dea1274aac834e5f79034ed 100644 (file)
@@ -449,11 +449,12 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
                return warn_unsupported(file, "read");
 
        init_sync_kiocb(&kiocb, file);
-       kiocb.ki_pos = *pos;
+       kiocb.ki_pos = pos ? *pos : 0;
        iov_iter_kvec(&iter, READ, &iov, 1, iov.iov_len);
        ret = file->f_op->read_iter(&kiocb, &iter);
        if (ret > 0) {
-               *pos = kiocb.ki_pos;
+               if (pos)
+                       *pos = kiocb.ki_pos;
                fsnotify_access(file);
                add_rchar(current, ret);
        }