diff mbox series

[01/13] fs: Allow a NULL pos pointer to __kernel_write

Message ID 20201003025534.21045-2-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Clean up kernel_read/kernel_write | expand

Commit Message

Matthew Wilcox Oct. 3, 2020, 2:55 a.m. UTC
Linus prefers that callers be allowed to pass in a NULL pointer for ppos
like new_sync_write().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/read_write.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Oct. 15, 2020, 5:56 p.m. UTC | #1
On Sat, Oct 03, 2020 at 03:55:22AM +0100, Matthew Wilcox (Oracle) wrote:
> Linus prefers that callers be allowed to pass in a NULL pointer for ppos
> like new_sync_write().
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/fs/read_write.c b/fs/read_write.c
index d835b5c86fae..7ee07f76fafc 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -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);
 	}