[PATCH] fs: prefer read_iter over read and write_iter over write

From: Jason A. Donenfeld
Date: Fri May 20 2022 - 09:51:23 EST


Most kernel code prefers read_iter over read and write_iter over write,
yet the read function pointer is tested first. Reverse these so that the
iter function is always used first.

Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: Jens Axboe <axboe@xxxxxxxxx>
Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
---
fs/read_write.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index e643aec2b0ef..78a81aa5fa76 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -476,10 +476,10 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
if (count > MAX_RW_COUNT)
count = MAX_RW_COUNT;

- if (file->f_op->read)
- ret = file->f_op->read(file, buf, count, pos);
- else if (file->f_op->read_iter)
+ if (file->f_op->read_iter)
ret = new_sync_read(file, buf, count, pos);
+ else if (file->f_op->read)
+ ret = file->f_op->read(file, buf, count, pos);
else
ret = -EINVAL;
if (ret > 0) {
@@ -585,10 +585,10 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
if (count > MAX_RW_COUNT)
count = MAX_RW_COUNT;
file_start_write(file);
- if (file->f_op->write)
- ret = file->f_op->write(file, buf, count, pos);
- else if (file->f_op->write_iter)
+ if (file->f_op->write_iter)
ret = new_sync_write(file, buf, count, pos);
+ else if (file->f_op->write)
+ ret = file->f_op->write(file, buf, count, pos);
else
ret = -EINVAL;
if (ret > 0) {
--
2.35.1