[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-386-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:18:45 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 385/437] speakup: convert to read/write iterators
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
drivers/accessibility/speakup/devsynth.c | 27 +++++-------
drivers/accessibility/speakup/speakup_soft.c | 46 +++++++++-----------
2 files changed, 31 insertions(+), 42 deletions(-)
diff --git a/drivers/accessibility/speakup/devsynth.c b/drivers/accessibility/speakup/devsynth.c
index cb7e1114e8eb..dd65b3882344 100644
--- a/drivers/accessibility/speakup/devsynth.c
+++ b/drivers/accessibility/speakup/devsynth.c
@@ -11,11 +11,10 @@ static int synth_registered, synthu_registered;
static int dev_opened;
/* Latin1 version */
-static ssize_t speakup_file_write(struct file *fp, const char __user *buffer,
- size_t nbytes, loff_t *ppos)
+static ssize_t speakup_file_write(struct kiocb *iocb, struct iov_iter *from)
{
+ size_t nbytes = iov_iter_count(from);
size_t count = nbytes;
- const char __user *ptr = buffer;
size_t bytes;
unsigned long flags;
u_char buf[256];
@@ -24,10 +23,9 @@ static ssize_t speakup_file_write(struct file *fp, const char __user *buffer,
return -ENODEV;
while (count > 0) {
bytes = min(count, sizeof(buf));
- if (copy_from_user(buf, ptr, bytes))
+ if (!copy_from_iter_full(buf, bytes, from))
return -EFAULT;
count -= bytes;
- ptr += bytes;
spin_lock_irqsave(&speakup_info.spinlock, flags);
synth_write(buf, bytes);
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
@@ -36,11 +34,10 @@ static ssize_t speakup_file_write(struct file *fp, const char __user *buffer,
}
/* UTF-8 version */
-static ssize_t speakup_file_writeu(struct file *fp, const char __user *buffer,
- size_t nbytes, loff_t *ppos)
+static ssize_t speakup_file_writeu(struct kiocb *iocb, struct iov_iter *from)
{
+ size_t nbytes = iov_iter_count(from);
size_t count = nbytes, want;
- const char __user *ptr = buffer;
size_t bytes;
unsigned long flags;
unsigned char buf[256];
@@ -54,7 +51,7 @@ static ssize_t speakup_file_writeu(struct file *fp, const char __user *buffer,
while (count >= want) {
/* Copy some UTF-8 piece from userland */
bytes = min(count, sizeof(buf));
- if (copy_from_user(buf, ptr, bytes))
+ if (!copy_from_iter_full(buf, bytes, from))
return -EFAULT;
/* Convert to u16 */
@@ -112,7 +109,6 @@ static ssize_t speakup_file_writeu(struct file *fp, const char __user *buffer,
}
count -= bytes;
- ptr += bytes;
/* And speak this up */
if (out) {
@@ -127,8 +123,7 @@ static ssize_t speakup_file_writeu(struct file *fp, const char __user *buffer,
return (ssize_t)(nbytes - count);
}
-static ssize_t speakup_file_read(struct file *fp, char __user *buf,
- size_t nbytes, loff_t *ppos)
+static ssize_t speakup_file_read(struct kiocb *iocb, struct iov_iter *to)
{
return 0;
}
@@ -149,15 +144,15 @@ static int speakup_file_release(struct inode *ip, struct file *fp)
}
static const struct file_operations synth_fops = {
- .read = speakup_file_read,
- .write = speakup_file_write,
+ .read_iter = speakup_file_read,
+ .write_iter = speakup_file_write,
.open = speakup_file_open,
.release = speakup_file_release,
};
static const struct file_operations synthu_fops = {
- .read = speakup_file_read,
- .write = speakup_file_writeu,
+ .read_iter = speakup_file_read,
+ .write_iter = speakup_file_writeu,
.open = speakup_file_open,
.release = speakup_file_release,
};
diff --git a/drivers/accessibility/speakup/speakup_soft.c b/drivers/accessibility/speakup/speakup_soft.c
index 6d446824677b..bc88e7e25910 100644
--- a/drivers/accessibility/speakup/speakup_soft.c
+++ b/drivers/accessibility/speakup/speakup_soft.c
@@ -215,17 +215,17 @@ static int softsynth_close(struct inode *inode, struct file *fp)
return 0;
}
-static ssize_t softsynthx_read(struct file *fp, char __user *buf, size_t count,
- loff_t *pos, int unicode)
+static ssize_t softsynthx_read(struct kiocb *iocb, struct iov_iter *to,
+ int unicode)
{
int chars_sent = 0;
- char __user *cp;
char *init;
size_t bytes_per_ch = unicode ? 3 : 1;
u16 ch;
int empty;
unsigned long flags;
DEFINE_WAIT(wait);
+ size_t count = iov_iter_count(to);
if (count < bytes_per_ch)
return -EINVAL;
@@ -241,7 +241,7 @@ static ssize_t softsynthx_read(struct file *fp, char __user *buf, size_t count,
break;
}
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
- if (fp->f_flags & O_NONBLOCK) {
+ if (iocb->ki_filp->f_flags & O_NONBLOCK) {
finish_wait(&speakup_event, &wait);
return -EAGAIN;
}
@@ -254,7 +254,6 @@ static ssize_t softsynthx_read(struct file *fp, char __user *buf, size_t count,
}
finish_wait(&speakup_event, &wait);
- cp = buf;
init = get_initstring();
/* Keep 3 bytes available for a 16bit UTF-8-encoded character */
@@ -278,22 +277,20 @@ static ssize_t softsynthx_read(struct file *fp, char __user *buf, size_t count,
if ((!unicode && ch < 0x100) || (unicode && ch < 0x80)) {
u_char c = ch;
- if (copy_to_user(cp, &c, 1))
+ if (!copy_to_iter_full(&c, 1, to))
return -EFAULT;
chars_sent++;
- cp++;
} else if (unicode && ch < 0x800) {
u_char s[2] = {
0xc0 | (ch >> 6),
0x80 | (ch & 0x3f)
};
- if (copy_to_user(cp, s, sizeof(s)))
+ if (!copy_to_iter_full(s, sizeof(s), to))
return -EFAULT;
chars_sent += sizeof(s);
- cp += sizeof(s);
} else if (unicode) {
u_char s[3] = {
0xe0 | (ch >> 12),
@@ -301,46 +298,43 @@ static ssize_t softsynthx_read(struct file *fp, char __user *buf, size_t count,
0x80 | (ch & 0x3f)
};
- if (copy_to_user(cp, s, sizeof(s)))
+ if (!copy_to_iter_full(s, sizeof(s), to))
return -EFAULT;
chars_sent += sizeof(s);
- cp += sizeof(s);
}
spin_lock_irqsave(&speakup_info.spinlock, flags);
}
- *pos += chars_sent;
+ iocb->ki_pos += chars_sent;
empty = synth_buffer_empty();
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
if (empty) {
speakup_start_ttys();
- *pos = 0;
+ iocb->ki_pos = 0;
}
return chars_sent;
}
-static ssize_t softsynth_read(struct file *fp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t softsynth_read(struct kiocb *iocb, struct iov_iter *to)
{
- return softsynthx_read(fp, buf, count, pos, 0);
+ return softsynthx_read(iocb, to, 0);
}
-static ssize_t softsynthu_read(struct file *fp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t softsynthu_read(struct kiocb *iocb, struct iov_iter *to)
{
- return softsynthx_read(fp, buf, count, pos, 1);
+ return softsynthx_read(iocb, to, 1);
}
static int last_index;
-static ssize_t softsynth_write(struct file *fp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t softsynth_write(struct kiocb *iocb, struct iov_iter *from)
{
unsigned long supplied_index = 0;
+ size_t count = iov_iter_count(from);
int converted;
- converted = kstrtoul_from_user(buf, count, 0, &supplied_index);
+ converted = kstrtoul_from_iter(from, count, 0, &supplied_index);
if (converted < 0)
return converted;
@@ -376,8 +370,8 @@ static unsigned char get_index(struct spk_synth *synth)
static const struct file_operations softsynth_fops = {
.owner = THIS_MODULE,
.poll = softsynth_poll,
- .read = softsynth_read,
- .write = softsynth_write,
+ .read_iter = softsynth_read,
+ .write_iter = softsynth_write,
.open = softsynth_open,
.release = softsynth_close,
};
@@ -385,8 +379,8 @@ static const struct file_operations softsynth_fops = {
static const struct file_operations softsynthu_fops = {
.owner = THIS_MODULE,
.poll = softsynth_poll,
- .read = softsynthu_read,
- .write = softsynth_write,
+ .read_iter = softsynthu_read,
+ .write_iter = softsynth_write,
.open = softsynth_open,
.release = softsynth_close,
};
--
2.43.0
Powered by blists - more mailing lists