[PATCH 013/437] char/apm-emulation: convert to read/write iterators

From: Jens Axboe
Date: Thu Apr 11 2024 - 11:38:41 EST


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
drivers/char/apm-emulation.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c
index e795390b070f..6b0ea84cf9c6 100644
--- a/drivers/char/apm-emulation.c
+++ b/drivers/char/apm-emulation.c
@@ -31,6 +31,7 @@
#include <linux/completion.h>
#include <linux/kthread.h>
#include <linux/delay.h>
+#include <linux/uio.h>

/*
* One option can be changed at boot time as follows:
@@ -200,9 +201,11 @@ static void queue_event(apm_event_t event)
wake_up_interruptible(&apm_waitqueue);
}

-static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t apm_read(struct kiocb *iocb, struct iov_iter *to)
{
+ struct file *fp = iocb->ki_filp;
struct apm_user *as = fp->private_data;
+ size_t count = iov_iter_count(to);
apm_event_t event;
int i = count, ret = 0;

@@ -218,7 +221,7 @@ static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t
event = queue_get_event(&as->queue);

ret = -EFAULT;
- if (copy_to_user(buf, &event, sizeof(event)))
+ if (!copy_to_iter_full(&event, sizeof(event), to))
break;

mutex_lock(&state_lock);
@@ -227,7 +230,6 @@ static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t
as->suspend_state = SUSPEND_READ;
mutex_unlock(&state_lock);

- buf += sizeof(event);
i -= sizeof(event);
}

@@ -379,7 +381,7 @@ static int apm_open(struct inode * inode, struct file * filp)

static const struct file_operations apm_bios_fops = {
.owner = THIS_MODULE,
- .read = apm_read,
+ .read_iter = apm_read,
.poll = apm_poll,
.unlocked_ioctl = apm_ioctl,
.open = apm_open,
--
2.43.0