fs: Allow a NULL pos pointer to __kernel_read

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>
This commit is contained in:
Matthew Wilcox (Oracle) 2020-10-03 03:55:23 +01:00 committed by Al Viro
parent 4c207ef482
commit 7b84b665c8

View 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"); return warn_unsupported(file, "read");
init_sync_kiocb(&kiocb, file); 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); iov_iter_kvec(&iter, READ, &iov, 1, iov.iov_len);
ret = file->f_op->read_iter(&kiocb, &iter); ret = file->f_op->read_iter(&kiocb, &iter);
if (ret > 0) { if (ret > 0) {
*pos = kiocb.ki_pos; if (pos)
*pos = kiocb.ki_pos;
fsnotify_access(file); fsnotify_access(file);
add_rchar(current, ret); add_rchar(current, ret);
} }