fs: Allow a NULL pos pointer to __kernel_write

Linus prefers that callers be allowed to pass in a NULL pointer for ppos
like new_sync_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:22 +01:00 committed by Al Viro
parent 5ae4998b5d
commit 4c207ef482
1 changed files with 3 additions and 2 deletions

View File

@ -544,11 +544,12 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t
return warn_unsupported(file, "write");
init_sync_kiocb(&kiocb, file);
kiocb.ki_pos = *pos;
kiocb.ki_pos = pos ? *pos : 0;
iov_iter_kvec(&iter, WRITE, &iov, 1, iov.iov_len);
ret = file->f_op->write_iter(&kiocb, &iter);
if (ret > 0) {
*pos = kiocb.ki_pos;
if (pos)
*pos = kiocb.ki_pos;
fsnotify_modify(file);
add_wchar(current, ret);
}