[PATCH 118/437] drivers/tty: convert to ->read_iter and ->write_iter
From: Jens Axboe
Date: Thu Apr 11 2024 - 12:23:11 EST
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
drivers/tty/serial/pch_uart.c | 9 ++++-----
drivers/tty/vt/vc_screen.c | 32 +++++++++++++++-----------------
2 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index 89257cddf540..a61410eb67b1 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -290,10 +290,9 @@ static const int trigger_level_1[4] = { 1, 1, 1, 1 };
#define PCH_REGS_BUFSIZE 1024
-static ssize_t port_show_regs(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t port_show_regs(struct kiocb *iocb, struct iov_iter *to)
{
- struct eg20t_port *priv = file->private_data;
+ struct eg20t_port *priv = iocb->ki_filp->private_data;
char *buf;
u32 len = 0;
ssize_t ret;
@@ -335,7 +334,7 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
if (len > PCH_REGS_BUFSIZE)
len = PCH_REGS_BUFSIZE;
- ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
+ ret = simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
kfree(buf);
return ret;
}
@@ -343,7 +342,7 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
static const struct file_operations port_regs_ops = {
.owner = THIS_MODULE,
.open = simple_open,
- .read = port_show_regs,
+ .read_iter = port_show_regs,
.llseek = default_llseek,
};
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index 67e2cb7c96ee..56daaa568866 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -361,10 +361,10 @@ static unsigned int vcs_read_buf(const struct vc_data *vc, char *con_buf,
return filled;
}
-static ssize_t
-vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t vcs_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct inode *inode = file_inode(file);
+ struct inode *inode = file_inode(iocb->ki_filp);
+ size_t count = iov_iter_count(to);
struct vc_data *vc;
struct vcs_poll_data *poll;
unsigned int read;
@@ -377,7 +377,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
if (!con_buf)
return -ENOMEM;
- pos = *ppos;
+ pos = iocb->ki_pos;
/* Select the proper current console and verify
* sanity of the situation under the console lock.
@@ -394,7 +394,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
if (uni_mode && (pos | count) & 3)
goto unlock_out;
- poll = file->private_data;
+ poll = iocb->ki_filp->private_data;
if (count && poll)
poll->event = 0;
read = 0;
@@ -453,7 +453,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
*/
console_unlock();
- ret = copy_to_user(buf, con_buf + skip, this_round);
+ ret = !copy_to_iter_full(con_buf + skip, this_round, to);
console_lock();
if (ret) {
@@ -461,12 +461,11 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
ret = -EFAULT;
break;
}
- buf += this_round;
pos += this_round;
read += this_round;
count -= this_round;
}
- *ppos += read;
+ iocb->ki_pos += read;
if (read)
ret = read;
unlock_out:
@@ -586,10 +585,10 @@ static u16 *vcs_write_buf(struct vc_data *vc, const char *con_buf,
return org;
}
-static ssize_t
-vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
+static ssize_t vcs_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct inode *inode = file_inode(file);
+ struct inode *inode = file_inode(iocb->ki_filp);
+ size_t count = iov_iter_count(from);
struct vc_data *vc;
char *con_buf;
u16 *org0, *org;
@@ -606,7 +605,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
if (!con_buf)
return -ENOMEM;
- pos = *ppos;
+ pos = iocb->ki_pos;
/* Select the proper current console and verify
* sanity of the situation under the console lock.
@@ -640,7 +639,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
* in the write data from userspace safely.
*/
console_unlock();
- ret = copy_from_user(con_buf, buf, this_round);
+ ret = !copy_from_iter_full(con_buf, this_round, from);
console_lock();
if (ret) {
@@ -692,12 +691,11 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
count -= this_round;
written += this_round;
- buf += this_round;
pos += this_round;
if (org)
update_region(vc, (unsigned long)(org0), org - org0);
}
- *ppos += written;
+ iocb->ki_pos += written;
ret = written;
if (written)
vcs_scr_updated(vc);
@@ -778,8 +776,8 @@ static int vcs_release(struct inode *inode, struct file *file)
static const struct file_operations vcs_fops = {
.llseek = vcs_lseek,
- .read = vcs_read,
- .write = vcs_write,
+ .read_iter = vcs_read,
+ .write_iter = vcs_write,
.poll = vcs_poll,
.fasync = vcs_fasync,
.open = vcs_open,
--
2.43.0